From 801b2fee9ab28d89aefeeb2d7406cf17eae9117a Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 5 Sep 2018 16:34:44 +1200 Subject: Implement logout button --- modern/src/LoginPage.js | 92 ++++++++++++++++++++++++----------------------- modern/src/MainPage.js | 2 +- modern/src/MainToolbar.js | 19 ++++++---- 3 files changed, 62 insertions(+), 51 deletions(-) (limited to 'modern') diff --git a/modern/src/LoginPage.js b/modern/src/LoginPage.js index 3ba6bacb..ac4a51ce 100644 --- a/modern/src/LoginPage.js +++ b/modern/src/LoginPage.js @@ -65,7 +65,8 @@ class LoginPage extends Component { // TODO implement registration } - handleLogin() { + handleLogin(event) { + event.preventDefault(); const { email, password } = this.state; fetch("/api/session", { method: "POST", @@ -91,49 +92,52 @@ class LoginPage extends Component { Traccar - - Email - - { failed && Invalid username or password } - - - - Password - - - -
- - - - - -
+
+ + + Email + + { failed && Invalid username or password } + + + + Password + + + +
+ + + + + +
+ +
diff --git a/modern/src/MainPage.js b/modern/src/MainPage.js index 36181a98..6db458ec 100644 --- a/modern/src/MainPage.js +++ b/modern/src/MainPage.js @@ -45,7 +45,7 @@ class MainPage extends Component { } else { return (
- +
diff --git a/modern/src/MainToolbar.js b/modern/src/MainToolbar.js index 1420135f..0a21d945 100644 --- a/modern/src/MainToolbar.js +++ b/modern/src/MainToolbar.js @@ -10,16 +10,23 @@ import MenuIcon from '@material-ui/icons/Menu'; const styles = { flex: { flexGrow: 1 - }, - menuButton: { - marginLeft: -12, - marginRight: 20 - }, + } }; class MainToobar extends Component { constructor(props) { super(props); + this.handleLogout = this.handleLogout.bind(this); + } + + handleLogout() { + fetch("/api/session", { + method: "DELETE" + }).then(response => { + if (response.ok) { + this.props.history.push('/login'); + } + }); } render() { @@ -33,7 +40,7 @@ class MainToobar extends Component { Traccar - + ); -- cgit v1.2.3