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) { login(userName, userPassword, doRemember) {
cookies.remove('auth');
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.userName = userName; this.userName = userName;
this.userPassword = userPassword; this.userPassword = userPassword;
@ -114,13 +113,16 @@ class Api {
} }
logout() { logout() {
cookies.remove('auth');
this.user = null; this.user = null;
this.userName = null; this.userName = null;
this.userPassword = null; this.userPassword = null;
events.notify(events.Authentication); events.notify(events.Authentication);
} }
forget() {
cookies.remove('auth');
}
isLoggedIn() { isLoggedIn() {
return this.userName !== null; return this.userName !== null;
} }

View file

@ -28,6 +28,7 @@ class AuthController {
this.loginView.render({ this.loginView.render({
login: (name, password, doRemember) => { login: (name, password, doRemember) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
api.forget();
api.login(name, password, doRemember) api.login(name, password, doRemember)
.then(() => { .then(() => {
resolve(); resolve();
@ -42,6 +43,7 @@ class AuthController {
} }
logoutRoute() { logoutRoute() {
api.forget();
api.logout(); api.logout();
page('/'); page('/');
events.notify(events.Success, 'Logged out'); events.notify(events.Success, 'Logged out');
@ -56,6 +58,7 @@ class AuthController {
} }
passwordResetFinishRoute(name, token) { passwordResetFinishRoute(name, token) {
api.forget();
api.logout(); api.logout();
api.post('/password-reset/' + name, {token: token}) api.post('/password-reset/' + name, {token: token})
.then(response => { .then(response => {
@ -76,6 +79,7 @@ class AuthController {
} }
_passwordReset(nameOrEmail) { _passwordReset(nameOrEmail) {
api.forget();
api.logout(); api.logout();
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
api.get('/password-reset/' + nameOrEmail) api.get('/password-reset/' + nameOrEmail)

View file

@ -85,6 +85,7 @@ class UsersController {
}; };
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
api.post('/users/', data).then(() => { api.post('/users/', data).then(() => {
api.forget();
api.login(name, password, false).then(() => { api.login(name, password, false).then(() => {
resolve(); resolve();
page('/'); page('/');
@ -142,6 +143,7 @@ class UsersController {
api.delete('/user/' + user.name) api.delete('/user/' + user.name)
.then(response => { .then(response => {
if (isLoggedIn) { if (isLoggedIn) {
api.forget();
api.logout(); api.logout();
} }
resolve(); resolve();