szurubooru/static/js/controllers/auth_controller.js
2016-03-30 20:45:37 +02:00

40 lines
1.3 KiB
JavaScript

'use strict';
const page = require('page');
const config = require('../config.js');
class AuthController {
constructor(api, topNavigationController, loginView) {
this.api = api;
this.topNavigationController = topNavigationController;
this.loginView = loginView;
/* TODO: load from cookies */
}
loginRoute() {
this.topNavigationController.activate('login');
this.loginView.render({
login: (userName, userPassword, doRemember) => {
return new Promise((resolve, reject) => {
this.api.login(userName, userPassword);
this.api.get('/user/' + userName)
.then(response => {
if (doRemember) {
/* TODO: set cookie */
}
resolve();
page('/');
/* TODO: update top navigation */
})
.catch(response => { reject(response.description); });
});
}});
}
logoutRoute() {
this.topNavigationController.activate('logout');
/* TODO: clear cookie */
}
}
module.exports = AuthController;