diff --git a/client/js/api.js b/client/js/api.js index 766fb47..2a41b2f 100644 --- a/client/js/api.js +++ b/client/js/api.js @@ -88,7 +88,6 @@ class Api { } login(userName, userPassword, doRemember) { - cookies.remove('auth'); return new Promise((resolve, reject) => { this.userName = userName; this.userPassword = userPassword; @@ -114,13 +113,16 @@ class Api { } logout() { - cookies.remove('auth'); this.user = null; this.userName = null; this.userPassword = null; events.notify(events.Authentication); } + forget() { + cookies.remove('auth'); + } + isLoggedIn() { return this.userName !== null; } diff --git a/client/js/controllers/auth_controller.js b/client/js/controllers/auth_controller.js index 80e32dc..4f724d5 100644 --- a/client/js/controllers/auth_controller.js +++ b/client/js/controllers/auth_controller.js @@ -28,6 +28,7 @@ class AuthController { this.loginView.render({ login: (name, password, doRemember) => { return new Promise((resolve, reject) => { + api.forget(); api.login(name, password, doRemember) .then(() => { resolve(); @@ -42,6 +43,7 @@ class AuthController { } logoutRoute() { + api.forget(); api.logout(); page('/'); events.notify(events.Success, 'Logged out'); @@ -56,6 +58,7 @@ class AuthController { } passwordResetFinishRoute(name, token) { + api.forget(); api.logout(); api.post('/password-reset/' + name, {token: token}) .then(response => { @@ -76,6 +79,7 @@ class AuthController { } _passwordReset(nameOrEmail) { + api.forget(); api.logout(); return new Promise((resolve, reject) => { api.get('/password-reset/' + nameOrEmail) diff --git a/client/js/controllers/users_controller.js b/client/js/controllers/users_controller.js index d242c1f..db35a02 100644 --- a/client/js/controllers/users_controller.js +++ b/client/js/controllers/users_controller.js @@ -85,6 +85,7 @@ class UsersController { }; return new Promise((resolve, reject) => { api.post('/users/', data).then(() => { + api.forget(); api.login(name, password, false).then(() => { resolve(); page('/'); @@ -142,6 +143,7 @@ class UsersController { api.delete('/user/' + user.name) .then(response => { if (isLoggedIn) { + api.forget(); api.logout(); } resolve();