Show if recovery key is valid

This commit is contained in:
David Baker 2018-09-17 17:05:29 +01:00
parent 9a65e6817a
commit f507aac3d5
5 changed files with 52 additions and 2 deletions

View file

@ -24,6 +24,10 @@ import Promise from 'bluebird';
import { _t, _td } from '../../../../languageHandler';
function isRecoveryKeyValid(r) {
return MatrixClientPeg.get().isValidRecoveryKey(r.replace(/ /g, ''));
}
/**
* Dialog for restoring e2e keys from a backup and the user's recovery key
*/
@ -36,6 +40,7 @@ export default React.createClass({
restoreError: null,
recoveryKey: "",
recoverInfo: null,
recoveryKeyValid: false,
};
},
@ -52,7 +57,10 @@ export default React.createClass({
},
_onRecoveryKeyChange: function(e) {
this.setState({recoveryKey: e.target.value});
this.setState({
recoveryKey: e.target.value,
recoveryKeyValid: isRecoveryKeyValid(e.target.value),
});
},
_onRecoverClick: async function() {
@ -125,6 +133,20 @@ export default React.createClass({
</div>;
} else {
const DialogButtons = sdk.getComponent('views.elements.DialogButtons');
let keyStatus;
if (this.state.recoveryKey.length === 0) {
keyStatus = <div className="mx_RestoreKeyBackupDialog_keyStatus"></div>;
} else if (this.state.recoveryKeyValid) {
keyStatus = <div className="mx_RestoreKeyBackupDialog_keyStatus">
{"\uD83D\uDC4D "}{_t("This looks like a valid recovery key!")}
</div>;
} else {
keyStatus = <div className="mx_RestoreKeyBackupDialog_keyStatus">
{"\uD83D\uDC4E "}{_t("Not a valid recovery key")}
</div>;
}
content = <div>
{_t("Please enter the recovery key generated when you set up key backup")}<br />
<textarea
@ -133,11 +155,13 @@ export default React.createClass({
style={{width: "90%"}}
autoFocus={true}
/>
{keyStatus}
<DialogButtons primaryButton={_t('Recover')}
onPrimaryButtonClick={this._onRecoverClick}
hasCancel={true}
onCancel={this._onCancel}
focus={false}
primaryDisabled={!this.state.recoveryKeyValid}
/>
</div>;
}

View file

@ -43,7 +43,11 @@ module.exports = React.createClass({
focus: PropTypes.bool,
// disables the primary and cancel buttons
disabled: PropTypes.bool,
// disables only the primary button
primaryDisabled: PropTypes.bool,
},
getDefaultProps: function() {
@ -73,7 +77,7 @@ module.exports = React.createClass({
<button className={primaryButtonClassName}
onClick={this.props.onPrimaryButtonClick}
autoFocus={this.props.focus}
disabled={this.props.disabled}
disabled={this.props.disabled || this.props.primaryDisabled}
>
{ this.props.primaryButton }
</button>

View file

@ -972,6 +972,8 @@
"No backup found!": "No backup found!",
"Failed to decrypt %(failedCount)s sessions!": "Failed to decrypt %(failedCount)s sessions!",
"Restored %(sessionCount)s session keys": "Restored %(sessionCount)s session keys",
"This looks like a valid recovery key!": "This looks like a valid recovery key!",
"Not a valid recovery key": "Not a valid recovery key",
"Please enter the recovery key generated when you set up key backup": "Please enter the recovery key generated when you set up key backup",
"Recover": "Recover",
"Restore Key Backup": "Restore Key Backup",