front/auth: move auth state to API

This commit is contained in:
rr-
2016-03-30 20:45:37 +02:00
parent 851bbc4b60
commit e95ed4cc0b
4 changed files with 38 additions and 41 deletions

View File

@ -8,42 +8,16 @@ class AuthController {
this.api = api;
this.topNavigationController = topNavigationController;
this.loginView = loginView;
this.currentUser = null;
/* TODO: load from cookies */
}
isLoggedIn() {
return this.currentUser !== null;
}
hasPrivilege() {
return true;
}
login(userName, userPassword) {
return new Promise((resolve, reject) => {
this.api.userName = userName;
this.api.userPassword = userPassword;
this.api.get('/user/' + userName)
.then(resolve)
.catch(reject);
});
}
logout(user) {
this.currentUser = null;
this.api.userName = null;
this.api.userPassword = null;
/* TODO: clear cookie */
}
loginRoute() {
this.topNavigationController.activate('login');
this.loginView.render({
login: (userName, userPassword, doRemember) => {
return new Promise((resolve, reject) => {
this
.login(userName, userPassword)
this.api.login(userName, userPassword);
this.api.get('/user/' + userName)
.then(response => {
if (doRemember) {
/* TODO: set cookie */
@ -59,6 +33,7 @@ class AuthController {
logoutRoute() {
this.topNavigationController.activate('logout');
/* TODO: clear cookie */
}
}