aboutsummaryrefslogtreecommitdiff
path: root/cmd/web/js/signin.jsx
blob: e0e0f1de8cfc4a962adb8eb6107c583debf15a1b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import Api from './api.js';
import App from './app.js';
import classNames from 'classnames';
import React from 'react';

class SigninForm extends React.Component {
  constructor(props) {
    super(props);
    this.state = {'hideMsg': true, 'msg': '', 'msgOk': false, 'password': '', 'email': ''};
  }

  handleSubmit = (e) => {
    Api.Call('SIGNIN', {'password': this.state.password, 'email': this.state.email}, function(err, status, data) {
      if (err) {
        console.error(err, data);
        this.displayMessage(App.errorCodeToMessage(err.code), false);
        return;
      }

      this.displayMessage('OK', true);
      this.props.onSuccess(data.token);

    }.bind(this));
    e.preventDefault();
  }

  handlePasswordChange = (event) => {
    this.setState({'password': event.target.value});
  }

  handleEmailChange = (event) => {
    this.setState({'email': event.target.value});
  }

  hideMessage = () => {
    this.setState({'hideMsg': true});
  }

  displayMessage = (msg, ok) => {
    this.setState({'msg': msg, 'msgOk': ok, 'hideMsg': false});
  }

  render = () => {
    var cName = classNames('form-message', {'hidden': this.state.hideMsg, 'message-ok': this.state.msgOk});
    return (
        <div className="row sign-in">
          <div className="offset-1 col-10 offset-md-4 col-md-4 text-center">
            <form role="form" onSubmit={this.handleSubmit}>
              <input className="form-control" type="email" placeholder="email" onChange={this.handleEmailChange} />
              <input className="form-control" type="password" placeholder="password" onChange={this.handlePasswordChange} />
              <input className="form-control submit" type="submit" value="Sign In" />
              <div className={cName}>{this.state.msg}</div>
            </form>
            <a href="#" onClick={App.onInternNavigation.bind(this, '/signup')}><u>Sign up</u></a>
          </div>
        </div>
       );
  }
}

export default SigninForm;