]>
Commit | Line | Data |
---|---|---|
989fb5c7 | 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 SigninForm extends React.Component { | |
7 | constructor(props) { | |
8 | super(props); | |
9 | this.state = {'hideMsg': true, 'msg': '', 'msgOk': false, 'password': '', 'email': ''}; | |
10 | } | |
11 | ||
12 | handleSubmit = (e) => { | |
7a9e5112 | 13 | Api.Call('SIGNIN', {'password': this.state.password, 'email': this.state.email}, function(err, status, data) { |
14 | if (err) { | |
15 | console.error(err, data); | |
16 | this.displayMessage(App.errorCodeToMessage(err.code), false); | |
17 | return; | |
18 | } | |
19 | ||
20 | this.displayMessage('OK', true); | |
6bf174a9 | 21 | this.props.onSuccess(data.token, data.isAdmin); |
7a9e5112 | 22 | |
23 | }.bind(this)); | |
24 | e.preventDefault(); | |
989fb5c7 | 25 | } |
26 | ||
27 | handlePasswordChange = (event) => { | |
7a9e5112 | 28 | this.setState({'password': event.target.value}); |
989fb5c7 | 29 | } |
30 | ||
31 | handleEmailChange = (event) => { | |
7a9e5112 | 32 | this.setState({'email': event.target.value}); |
989fb5c7 | 33 | } |
34 | ||
35 | hideMessage = () => { | |
7a9e5112 | 36 | this.setState({'hideMsg': true}); |
989fb5c7 | 37 | } |
38 | ||
39 | displayMessage = (msg, ok) => { | |
7a9e5112 | 40 | this.setState({'msg': msg, 'msgOk': ok, 'hideMsg': false}); |
989fb5c7 | 41 | } |
42 | ||
43 | render = () => { | |
7a9e5112 | 44 | var cName = classNames('form-message', {'hidden': this.state.hideMsg, 'message-ok': this.state.msgOk}); |
45 | return ( | |
a6820180 | 46 | <React.Fragment> |
989fb5c7 | 47 | <div className="row sign-in"> |
a6820180 | 48 | <div className="offset-1 col-10 box offset-md-4 col-md-4 text-center"> |
989fb5c7 | 49 | <form role="form" onSubmit={this.handleSubmit}> |
a6820180 | 50 | <label className="w-100 text-left"><strong>Email address</strong></label> |
51 | <input className="form-control" type="email" onChange={this.handleEmailChange} /> | |
52 | <span className="w-100 d-inline-block text-left"> | |
53 | <label><strong>Password</strong></label> | |
54 | <a className="blue-link hint-text float-right" href="/reset-password">Forgot password?</a> | |
55 | </span> | |
56 | <input className="form-control" type="password" onChange={this.handlePasswordChange} /> | |
989fb5c7 | 57 | <input className="form-control submit" type="submit" value="Sign In" /> |
58 | <div className={cName}>{this.state.msg}</div> | |
7a9e5112 | 59 | </form> |
7a9e5112 | 60 | </div> |
61 | </div> | |
a6820180 | 62 | <div className="row"> |
63 | <div className="offset-1 col-10 box offset-md-4 col-md-4 text-center"> | |
64 | <span>New to CryptoPF? <a href="#" className="blue-link" onClick={App.onInternNavigation.bind(this, '/signup')}>Create an account.</a></span> | |
65 | </div> | |
66 | </div> | |
67 | </React.Fragment> | |
7a9e5112 | 68 | ); |
69 | } | |
989fb5c7 | 70 | } |
71 | ||
72 | export default SigninForm; | |
7a9e5112 | 73 |