/
LoginPage.jsx
76 lines (66 loc) · 2.31 KB
/
LoginPage.jsx
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
63
64
65
66
67
68
69
70
71
72
73
74
75
import React from 'react';
import Reflux from 'reflux';
import { Row, Input, ButtonInput, Alert } from 'react-bootstrap';
import SessionActions from 'actions/sessions/SessionActions';
import SessionStore from 'stores/sessions/SessionStore';
import disconnectedStyle from '!style/useable!css!less!stylesheets/disconnected.less';
import authStyle from '!style/useable!css!less!stylesheets/auth.less';
const LoginPage = React.createClass({
mixins: [Reflux.connect(SessionStore), Reflux.ListenerMethods],
componentDidMount() {
disconnectedStyle.use();
authStyle.use();
},
componentWillUnmount() {
disconnectedStyle.unuse();
authStyle.unuse();
},
onSignInClicked(event) {
event.preventDefault();
this.resetLastError();
const username = this.refs.username.getValue();
const password = this.refs.password.getValue();
const location = document.location.host;
SessionActions.login.triggerPromise(username, password, location).catch((error) => {
if (error.additional.status === 401) {
this.setState({lastError: 'Invalid credentials, please verify them and retry.'});
} else {
this.setState({lastError: 'Error - the server returned: ' + error.additional.status + ' - ' + error.message});
}
});
},
formatLastError(error) {
if (error) {
return (
<div className="form-group">
<Alert bsStyle="danger">
<a className="close" onClick={this.resetLastError}>×</a>{error}
</Alert>
</div>
);
}
return null;
},
resetLastError() {
this.setState({lastError: undefined});
},
render() {
const alert = this.formatLastError(this.state.lastError);
return (
<div>
<div className="container" id="login-box">
<Row>
<form className="col-md-4 col-md-offset-4 well" id="login-box-content" onSubmit={this.onSignInClicked}>
<legend><i className="fa fa-group"/> Welcome to Graylog</legend>
{alert}
<Input ref="username" type="text" placeholder="Username" autoFocus />
<Input ref="password" type="password" placeholder="Password" />
<ButtonInput type="submit" bsStyle="info">Sign in</ButtonInput>
</form>
</Row>
</div>
</div>
);
},
});
export default LoginPage;