Merge pull request #890 from matrix-org/luke/new-guest-access-change-pwd

Make confirmation optional on ChangePassword
pull/21833/head
Luke Barnard 2017-05-16 14:05:19 +01:00 committed by GitHub
commit 49437e301e
1 changed files with 42 additions and 32 deletions

View File

@ -34,6 +34,7 @@ module.exports = React.createClass({
rowLabelClassName: React.PropTypes.string, rowLabelClassName: React.PropTypes.string,
rowInputClassName: React.PropTypes.string, rowInputClassName: React.PropTypes.string,
buttonClassName: React.PropTypes.string, buttonClassName: React.PropTypes.string,
confirm: React.PropTypes.bool,
}, },
Phases: { Phases: {
@ -56,7 +57,8 @@ module.exports = React.createClass({
error: "Passwords can't be empty" error: "Passwords can't be empty"
}; };
} }
} },
confirm: true,
}; };
}, },
@ -89,9 +91,14 @@ module.exports = React.createClass({
}, },
changePassword: function(old_password, new_password) { changePassword: function(old_password, new_password) {
var cli = MatrixClientPeg.get(); const cli = MatrixClientPeg.get();
var QuestionDialog = sdk.getComponent("dialogs.QuestionDialog"); if (!this.props.confirm) {
this._changePassword(cli, oldPassword, newPassword);
return;
}
const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
Modal.createDialog(QuestionDialog, { Modal.createDialog(QuestionDialog, {
title: "Warning", title: "Warning",
description: description:
@ -110,31 +117,34 @@ module.exports = React.createClass({
], ],
onFinished: (confirmed) => { onFinished: (confirmed) => {
if (confirmed) { if (confirmed) {
var authDict = { this._changePassword(cli, oldPassword, newPassword);
type: 'm.login.password',
user: cli.credentials.userId,
password: old_password
};
this.setState({
phase: this.Phases.Uploading
});
var self = this;
cli.setPassword(authDict, new_password).then(function() {
self.props.onFinished();
}, function(err) {
self.props.onError(err);
}).finally(function() {
self.setState({
phase: self.Phases.Edit
});
}).done();
} }
}, },
}); });
}, },
_changePassword: function(cli, oldPassword, newPassword) {
const authDict = {
type: 'm.login.password',
user: cli.credentials.userId,
password: oldPassword,
};
this.setState({
phase: this.Phases.Uploading,
});
cli.setPassword(authDict, newPassword).then(() => {
this.props.onFinished();
}, (err) => {
this.props.onError(err);
}).finally(() => {
this.setState({
phase: this.Phases.Edit,
});
}).done();
},
_onExportE2eKeysClicked: function() { _onExportE2eKeysClicked: function() {
Modal.createDialogAsync( Modal.createDialogAsync(
(cb) => { (cb) => {
@ -148,17 +158,16 @@ module.exports = React.createClass({
}, },
onClickChange: function() { onClickChange: function() {
var old_password = this.state.cachedPassword || this.refs.old_input.value; const oldPassword = this.refs.old_input.value;
var new_password = this.refs.new_input.value; const newPassword = this.refs.new_input.value;
var confirm_password = this.refs.confirm_input.value; const confirmPassword = this.refs.confirm_input.value;
var err = this.props.onCheckPassword( const err = this.props.onCheckPassword(
old_password, new_password, confirm_password oldPassword, newPassword, confirmPassword,
); );
if (err) { if (err) {
this.props.onError(err); this.props.onError(err);
} } else {
else { this.changePassword(oldPassword, newPassword);
this.changePassword(old_password, new_password);
} }
}, },
@ -202,7 +211,8 @@ module.exports = React.createClass({
</div> </div>
</div> </div>
<AccessibleButton className={buttonClassName} <AccessibleButton className={buttonClassName}
onClick={this.onClickChange}> onClick={this.onClickChange}
element="button">
Change Password Change Password
</AccessibleButton> </AccessibleButton>
</div> </div>