mirror of
https://github.com/franjsco/tick3t
synced 2025-06-05 22:19:18 +02:00
improvement: various
This commit is contained in:
@@ -9,7 +9,7 @@ import {
|
|||||||
Input
|
Input
|
||||||
} from 'reactstrap';
|
} from 'reactstrap';
|
||||||
|
|
||||||
import { config } from '../../config';
|
import { login } from '../../api/authentication';
|
||||||
|
|
||||||
import Card from '../../components/Card';
|
import Card from '../../components/Card';
|
||||||
import Button from '../../components/Button';
|
import Button from '../../components/Button';
|
||||||
@@ -44,46 +44,24 @@ class Login extends Component {
|
|||||||
|
|
||||||
const { email, password } = this.state;
|
const { email, password } = this.state;
|
||||||
|
|
||||||
const body = {
|
login(email, password)
|
||||||
email,
|
|
||||||
password
|
|
||||||
}
|
|
||||||
|
|
||||||
fetch(`${config.baseURL}users/login`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
body: JSON.stringify(body)
|
|
||||||
})
|
|
||||||
.then(res => {
|
|
||||||
return res.json();
|
|
||||||
})
|
|
||||||
.then((json) => {
|
.then((json) => {
|
||||||
if (!json.success) {
|
if (!json.success) {
|
||||||
this.setState({
|
this.setState({
|
||||||
error: json.message
|
error: json.message
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
localStorage.setItem('token', json.token);
|
localStorage.setItem('user', JSON.stringify(json.data));
|
||||||
this.setState({
|
this.setState({
|
||||||
success: true
|
success: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
if (err === 'AuthErr'){
|
this.setState({
|
||||||
this.setState({
|
error: err.message
|
||||||
err: 'auth error'
|
});
|
||||||
});
|
|
||||||
} else {
|
|
||||||
this.setState({
|
|
||||||
err: err.message
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resetLogin(event) {
|
resetLogin(event) {
|
||||||
@@ -97,10 +75,11 @@ class Login extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
||||||
if (this.state.error) {
|
if (this.state.error) {
|
||||||
return (
|
return (
|
||||||
<Card title="Error">
|
<Card
|
||||||
|
title="Error"
|
||||||
|
>
|
||||||
<p>{this.state.error}</p>
|
<p>{this.state.error}</p>
|
||||||
<a href="" onClick={this.resetLogin}>Back to login</a>
|
<a href="" onClick={this.resetLogin}>Back to login</a>
|
||||||
</Card>
|
</Card>
|
||||||
@@ -112,7 +91,7 @@ class Login extends Component {
|
|||||||
<Redirect to="/admin/" />
|
<Redirect to="/admin/" />
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card
|
<Card
|
||||||
align="left"
|
align="left"
|
||||||
|
Reference in New Issue
Block a user