client/api: fix removing cookies on login failures
This commit is contained in:
parent
2e1823b708
commit
e12492bd4d
3 changed files with 10 additions and 2 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue