From 02045858f75f9b53ef733fea0540f69da8c8e424 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 16 Jul 2015 10:23:31 +0100 Subject: [PATCH] Wire up change password --- skins/base/views/molecules/ChangePassword.js | 31 +++++++++++++++++--- src/controllers/molecules/ChangePassword.js | 31 +++++++++++++++++++- 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/skins/base/views/molecules/ChangePassword.js b/skins/base/views/molecules/ChangePassword.js index ff64a7216a..98b2e71bce 100644 --- a/skins/base/views/molecules/ChangePassword.js +++ b/skins/base/views/molecules/ChangePassword.js @@ -19,23 +19,39 @@ limitations under the License. var React = require('react'); var ChangePasswordController = require("../../../../src/controllers/molecules/ChangePassword"); +var Loader = require("react-loader"); module.exports = React.createClass({ displayName: 'ChangePassword', mixins: [ChangePasswordController], + onClickChange: function() { + var old_password = this.refs.old_input.getDOMNode().value; + var new_password = this.refs.new_input.getDOMNode().value; + var confirm_password = this.refs.confirm_input.getDOMNode().value; + if (new_password != confirm_password) { + this.setState({ + state: this.Phases.Error, + errorString: "Passwords don't match" + }); + } else { + this.changePassword(old_password, new_password); + } + }, + render: function() { switch (this.state.phase) { case this.Phases.Edit: case this.Phases.Error: return (
- - - +
{this.state.errorString}
+ + +
- +
@@ -44,6 +60,13 @@ module.exports = React.createClass({ return ( ); + case this.Phases.Success: + return ( +
+ Success! + +
+ ) } } }); diff --git a/src/controllers/molecules/ChangePassword.js b/src/controllers/molecules/ChangePassword.js index 6bbc14b6d9..d824119590 100644 --- a/src/controllers/molecules/ChangePassword.js +++ b/src/controllers/molecules/ChangePassword.js @@ -30,6 +30,7 @@ module.exports = { Edit: "edit", Uploading: "uploading", Error: "error", + Success: "Success" }, getDefaultProps: function() { @@ -41,10 +42,38 @@ module.exports = { getInitialState: function() { return { phase: this.Phases.Edit, + errorString: '' } }, changePassword: function(old_password, new_password) { - // DO SOMETHING. + var cli = MatrixClientPeg.get(); + + var authDict = { + type: 'm.login.password', + user: cli.credentials.userId, + password: old_password + }; + + this.setState({ + phase: this.Phases.Uploading, + errorString: '', + }) + + var d = cli.setPassword(authDict, new_password); + + var self = this; + d.then(function() { + self.setState({ + phase: self.Phases.Success, + errorString: '', + }) + // self.props.onFinished(); + }, function(err) { + self.setState({ + phase: self.Phases.Error, + errorString: err.toString() + }) + }); }, }