/
LoginPage.js
42 lines (38 loc) · 1.02 KB
/
LoginPage.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
import React, { Component } from 'react';
import { Header, Form, Segment } from 'semantic-ui-react';
export default class LoginPage extends Component {
constructor(props) {
super(props);
this.state = {
password: '',
error: null,
};
this.onSubmit = this.onSubmit.bind(this);
}
async onSubmit(e) {
const { password } = this.state;
const resp = await fetch('/api/auth?password=' + password);
if (resp.ok) {
this.setState({ error: null });
window.location = '/admin/';
} else {
this.setState({ error: 'Wrong password' });
}
}
render() {
return (
<Segment>
<Form onSubmit={this.onSubmit}>
<Header>Admin Login</Header>
<Form.Input
onChange={(e, { value }) => this.setState({ password: value })}
type="password"
label="Password"
/>
<Form.Button>Submit</Form.Button>
<p style={{ color: 'red' }}>{this.state.error}</p>
</Form>
</Segment>
);
}
}