From c1de0809d37eceb5194f5a9f8a76ebdea7504be8 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 5 Sep 2018 15:30:07 +1200 Subject: Improve login screen --- modern/src/LoginPage.js | 103 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 80 insertions(+), 23 deletions(-) (limited to 'modern/src') diff --git a/modern/src/LoginPage.js b/modern/src/LoginPage.js index 8b8401a..9934106 100644 --- a/modern/src/LoginPage.js +++ b/modern/src/LoginPage.js @@ -1,10 +1,10 @@ import React, { Component } from 'react'; import Button from '@material-ui/core/Button'; +import FormHelperText from '@material-ui/core/FormHelperText'; import FormControl from '@material-ui/core/FormControl'; import Input from '@material-ui/core/Input'; import InputLabel from '@material-ui/core/InputLabel'; import Paper from '@material-ui/core/Paper'; -import Typography from '@material-ui/core/Typography'; import withStyles from '@material-ui/core/styles/withStyles'; const styles = theme => ({ @@ -24,10 +24,19 @@ const styles = theme => ({ display: 'flex', flexDirection: 'column', alignItems: 'center', - padding: `${theme.spacing.unit * 2}px ${theme.spacing.unit * 3}px ${theme.spacing.unit * 3}px`, + padding: `${theme.spacing.unit * 3}px`, }, - submit: { - marginTop: theme.spacing.unit * 3, + logo: { + margin: `${theme.spacing.unit * 2}px 0 ${theme.spacing.unit}px` + }, + buttons: { + width: '100%', + display: 'flex', + flexDirection: 'row' + }, + button: { + flex: '1 1 0', + margin: `${theme.spacing.unit * 3}px ${theme.spacing.unit}px 0` }, }); @@ -35,22 +44,39 @@ class LoginPage extends Component { constructor(props) { super(props); this.state = { - failed: false + filled: false, + loading: false, + failed: false, + email: "", + password: "" }; - this.handleSubmit = this.handleSubmit.bind(this); + this.handleChange = this.handleChange.bind(this); + this.handleRegister = this.handleRegister.bind(this); + this.handleLogin = this.handleLogin.bind(this); } - handleSubmit() { - console.log(); + handleChange(event) { + this.setState({ + [event.target.id]: event.target.value + }); + } + + handleRegister() { + // TODO implement registration + } + + handleLogin() { + const { email, password } = this.state; fetch("/api/session", { method: "POST", - body: new URLSearchParams(`email=admin&password=admin`) + body: new URLSearchParams(`email=${email}&password=${password}`) }).then(response => { if (response.ok) { this.props.history.push('/'); // TODO avoid calling sessions twice } else { this.setState({ - failed: true + failed: true, + password: "" }); } }); @@ -58,26 +84,57 @@ class LoginPage extends Component { render() { const { classes } = this.props; - const { failed } = this.state; + const { failed, email, password } = this.state; return (
- Traccar - { - failed && - Login failed - } - - Email Address - + + Traccar + + + Email + + { failed && Invalid username or password } + Password - + - + +
+ + + + + +
+
); -- cgit v1.2.3