Skip to content

Commit 0204585

Browse files
committed
Wire up change password
1 parent edc3302 commit 0204585

2 files changed

Lines changed: 57 additions & 5 deletions

File tree

‎skins/base/views/molecules/ChangePassword.js‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,39 @@ limitations under the License.
1919
var React = require('react');
2020

2121
var ChangePasswordController = require("../../../../src/controllers/molecules/ChangePassword");
22+
var Loader = require("react-loader");
2223

2324

2425
module.exports = React.createClass({
2526
displayName: 'ChangePassword',
2627
mixins: [ChangePasswordController],
2728

29+
onClickChange: function() {
30+
var old_password = this.refs.old_input.getDOMNode().value;
31+
var new_password = this.refs.new_input.getDOMNode().value;
32+
var confirm_password = this.refs.confirm_input.getDOMNode().value;
33+
if (new_password != confirm_password) {
34+
this.setState({
35+
state: this.Phases.Error,
36+
errorString: "Passwords don't match"
37+
});
38+
} else {
39+
this.changePassword(old_password, new_password);
40+
}
41+
},
42+
2843
render: function() {
2944
switch (this.state.phase) {
3045
case this.Phases.Edit:
3146
case this.Phases.Error:
3247
return (
3348
<div>
34-
<label>Old password <input type="password" /></label>
35-
<label>New password <input type="password" /></label>
36-
<label>Confirm password <input type="password" /></label>
49+
<div>{this.state.errorString}</div>
50+
<label>Old password <input type="password" ref="old_input"/></label>
51+
<label>New password <input type="password" ref="new_input"/></label>
52+
<label>Confirm password <input type="password" ref="confirm_input"/></label>
3753
<div>
38-
<button>Change Password</button>
54+
<button onClick={this.onClickChange}>Change Password</button>
3955
<button onClick={this.props.onFinished}>Cancel</button>
4056
</div>
4157
</div>
@@ -44,6 +60,13 @@ module.exports = React.createClass({
4460
return (
4561
<Loader />
4662
);
63+
case this.Phases.Success:
64+
return (
65+
<div>
66+
Success!
67+
<button onClick={this.props.onFinished}>Ok</button>
68+
</div>
69+
)
4770
}
4871
}
4972
});

‎src/controllers/molecules/ChangePassword.js‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module.exports = {
3030
Edit: "edit",
3131
Uploading: "uploading",
3232
Error: "error",
33+
Success: "Success"
3334
},
3435

3536
getDefaultProps: function() {
@@ -41,10 +42,38 @@ module.exports = {
4142
getInitialState: function() {
4243
return {
4344
phase: this.Phases.Edit,
45+
errorString: ''
4446
}
4547
},
4648

4749
changePassword: function(old_password, new_password) {
48-
// DO SOMETHING.
50+
var cli = MatrixClientPeg.get();
51+
52+
var authDict = {
53+
type: 'm.login.password',
54+
user: cli.credentials.userId,
55+
password: old_password
56+
};
57+
58+
this.setState({
59+
phase: this.Phases.Uploading,
60+
errorString: '',
61+
})
62+
63+
var d = cli.setPassword(authDict, new_password);
64+
65+
var self = this;
66+
d.then(function() {
67+
self.setState({
68+
phase: self.Phases.Success,
69+
errorString: '',
70+
})
71+
// self.props.onFinished();
72+
}, function(err) {
73+
self.setState({
74+
phase: self.Phases.Error,
75+
errorString: err.toString()
76+
})
77+
});
4978
},
5079
}

0 commit comments

Comments
 (0)