const React = require('react'); const { connect } = require('react-redux'); const MasterKeys = require('lib/models/MasterKey'); const EncryptionService = require('lib/services/EncryptionService'); const { Header } = require('./Header.min.js'); const { themeStyle } = require('../theme.js'); const { _ } = require('lib/locale.js'); const { time } = require('lib/time-utils.js'); class MasterKeysScreenComponent extends React.Component { constructor() { super(); this.state = { masterKeys: [], passwords: {}, passwordChecks: {}, }; } componentWillMount() { this.setState({ masterKeys: this.props.masterKeys, passwords: this.props.passwords ? this.props.passwords : {}, }, () => { this.checkPasswords(); }); } async checkPasswords() { const passwordChecks = Object.assign({}, this.state.passwordChecks); for (let i = 0; i < this.state.masterKeys.length; i++) { const mk = this.state.masterKeys[i]; const password = this.state.passwords[mk.id]; const ok = password ? await EncryptionService.instance().checkMasterKeyPassword(mk, password) : false; passwordChecks[mk.id] = ok; } this.setState({ passwordChecks: passwordChecks }); } renderMasterKey(mk) { const onSaveClick = () => { const password = this.state.passwords[mk.id]; const cache = Setting.value('encryption.passwordCache'); if (!cache) cache = {}; if (!password) { delete cache[mk.id]; } else { cache[mk.id] = password; } Setting.setValue('encryption.passwordCache', cache); this.checkPasswords(); } const onPasswordChange = (event) => { const passwords = this.state.passwords; passwords[mk.id] = event.target.value; this.setState({ passwords: passwords }); } const password = this.state.passwords[mk.id] ? this.state.passwords[mk.id] : ''; const active = this.props.activeMasterKeyId === mk.id ? '✔' : ''; const passwordOk = this.state.passwordChecks[mk.id] === true ? '✔' : '❌'; return (
{_('Active')} | {_('ID')} | {_('Source')} | {_('Created')} | {_('Updated')} | {_('Password')} | {_('Password OK')} |
---|