diff options
Diffstat (limited to 'cmd/web/js/change_password.jsx')
-rw-r--r-- | cmd/web/js/change_password.jsx | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/cmd/web/js/change_password.jsx b/cmd/web/js/change_password.jsx new file mode 100644 index 0000000..aedf4af --- /dev/null +++ b/cmd/web/js/change_password.jsx | |||
@@ -0,0 +1,62 @@ | |||
1 | import Api from './api.js'; | ||
2 | import App from './app.js'; | ||
3 | import classNames from 'classnames'; | ||
4 | import React from 'react'; | ||
5 | |||
6 | class ChangePasswordForm extends React.Component { | ||
7 | constructor(props) { | ||
8 | super(props); | ||
9 | this.state = {'hideMsg': true, 'msg': '', 'msgOk': false, 'password': ''}; | ||
10 | } | ||
11 | |||
12 | handleSubmit = (e) => { | ||
13 | Api.Call( | ||
14 | 'CHANGE_PASSWORD', | ||
15 | { | ||
16 | 'password': this.state.password, | ||
17 | 'token': this.props.token | ||
18 | }, | ||
19 | function(err, status, data) { | ||
20 | if (err) { | ||
21 | console.error(err, data); | ||
22 | this.displayMessage(App.errorCodeToMessage(err.code), false); | ||
23 | return; | ||
24 | } | ||
25 | |||
26 | this.displayMessage('You password has been reset.', true); | ||
27 | this.props.onSuccess(); | ||
28 | |||
29 | }.bind(this) | ||
30 | ); | ||
31 | e.preventDefault(); | ||
32 | } | ||
33 | |||
34 | handlePasswordChange = (event) => { | ||
35 | this.setState({'password': event.target.value}); | ||
36 | } | ||
37 | |||
38 | hideMessage = () => { | ||
39 | this.setState({'hideMsg': true}); | ||
40 | } | ||
41 | |||
42 | displayMessage = (msg, ok) => { | ||
43 | this.setState({'msg': msg, 'msgOk': ok, 'hideMsg': false}); | ||
44 | } | ||
45 | |||
46 | render = () => { | ||
47 | var cName = classNames('form-message', {'hidden': this.state.hideMsg, 'message-ok': this.state.msgOk}); | ||
48 | return ( | ||
49 | <div className="row sign-in"> | ||
50 | <div className="offset-4 col-4 col-xs-offset-1 col-xs-10 text-center"> | ||
51 | <form role="form" onSubmit={this.handleSubmit}> | ||
52 | <input className="form-control" type="password" placeholder="password" onChange={this.handlePasswordChange} /> | ||
53 | <input className="form-control submit" type="submit" value="Change password" /> | ||
54 | <div className={cName}>{this.state.msg}</div> | ||
55 | </form> | ||
56 | </div> | ||
57 | </div> | ||
58 | ); | ||
59 | } | ||
60 | } | ||
61 | |||
62 | export default ChangePasswordForm; | ||