-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Login.js
54 lines (50 loc) · 1.6 KB
/
Login.js
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
import React, {Component, PropTypes} from 'react';
import {connect} from 'react-redux';
import Helmet from 'react-helmet';
import * as authActions from 'redux/modules/auth';
@connect(
state => ({user: state.auth.user}),
authActions)
export default class Login extends Component {
static propTypes = {
user: PropTypes.object,
login: PropTypes.func,
logout: PropTypes.func
}
handleSubmit = (event) => {
event.preventDefault();
const input = this.refs.username;
this.props.login(input.value);
input.value = '';
}
render() {
const {user, logout} = this.props;
const styles = require('./Login.scss');
return (
<div className={styles.loginPage + ' container'}>
<Helmet title="Login"/>
<h1>Login</h1>
{!user &&
<div>
<form className="login-form form-inline" onSubmit={this.handleSubmit}>
<div className="form-group">
<input type="text" ref="username" placeholder="Enter a username" className="form-control"/>
</div>
<button className="btn btn-success" onClick={this.handleSubmit}><i className="fa fa-sign-in"/>{' '}Log In
</button>
</form>
<p>This will "log you in" as this user, storing the username in the session of the API server.</p>
</div>
}
{user &&
<div>
<p>You are currently logged in as {user.name}.</p>
<div>
<button className="btn btn-danger" onClick={logout}><i className="fa fa-sign-out"/>{' '}Log Out</button>
</div>
</div>
}
</div>
);
}
}