Wire up change password

This commit is contained in:
Erik Johnston 2015-07-16 10:23:31 +01:00
parent edc3302d89
commit 02045858f7
2 changed files with 57 additions and 5 deletions

View File

@ -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 (
<div>
<label>Old password <input type="password" /></label>
<label>New password <input type="password" /></label>
<label>Confirm password <input type="password" /></label>
<div>{this.state.errorString}</div>
<label>Old password <input type="password" ref="old_input"/></label>
<label>New password <input type="password" ref="new_input"/></label>
<label>Confirm password <input type="password" ref="confirm_input"/></label>
<div>
<button>Change Password</button>
<button onClick={this.onClickChange}>Change Password</button>
<button onClick={this.props.onFinished}>Cancel</button>
</div>
</div>
@ -44,6 +60,13 @@ module.exports = React.createClass({
return (
<Loader />
);
case this.Phases.Success:
return (
<div>
Success!
<button onClick={this.props.onFinished}>Ok</button>
</div>
)
}
}
});

View File

@ -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()
})
});
},
}