client/api: fix removing cookies on login failures

This commit is contained in:
rr- 2016-04-09 19:53:53 +02:00
parent 2e1823b708
commit e12492bd4d
3 changed files with 10 additions and 2 deletions

View file

@ -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;
}

View file

@ -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)

View file

@ -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();