-
Notifications
You must be signed in to change notification settings - Fork 3
/
LoginWriter.js
75 lines (68 loc) · 2.34 KB
/
LoginWriter.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import React, { Component } from 'react';
import { Form, Input } from 'antd';
import { Redirect } from "react-router-dom";
import Button from '../../Components/Button';
import Portal from '../../Components/Portal';
import Logo from '../../Components/Logo';
import { loginWriterAPI } from '../../Services/WriterServices';
class LoginWriter extends Component {
constructor(props) {
super(props);
this.state = {
email: "",
password: "",
errMsg: "",
isSuccess: false,
}
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange = (event) => {
this.setState({[event.target.id]: event.target.value, errMsg: ""});
}
handleSubmit = async () => {
const response = await loginWriterAPI({"email": this.state.email, "password": this.state.password});
console.log(response.status)
if (response.status === 200)
{
localStorage.setItem('user', JSON.stringify(response.data));
if (localStorage.getItem('user'))
this.setState({isSuccess: true});
}
else
this.setState({errMsg: "Invalid email or password."})
}
render() {
return (
<div className="LoginAccount">
<Logo></Logo><br /><br /><br />
<Portal>
<Form onFinish={this.handleSubmit}>
<center><h2>Log In</h2></center><br />
<label for="email">Email</label><br />
<Form.Item
name="email"
rules={[{required: true, message: "Please enter a verified email"}]}>
<Input onChange={this.handleChange} />
</Form.Item>
<label for="password">Password</label><br />
<Form.Item
name="password"
rules={[{required: true, message: "Enter your passoword to login"}]}>
<Input.Password onChange={this.handleChange} />
</Form.Item>
<center>{!localStorage.getItem('user') ? <err>{this.state.errMsg}</err> : <Redirect to="/feed/" />}</center>
<br />
<Form.Item>
<center>
<Button class="normal">Log In</Button><br />
<a href="/account/create/">Don't have an account ?</a>
</center>
</Form.Item>
</Form>
</Portal>
</div>
);
}
}
export default LoginWriter;