aboutsummaryrefslogtreecommitdiff
path: root/static/js/controllers/auth_controller.js
diff options
context:
space:
mode:
authorrr-2016-03-30 21:01:18 +0200
committerrr-2016-03-30 21:04:00 +0200
commitbb474e4cf5568e1858649cf1675d02a08f4f5299 (patch)
tree0762578cbb944bc77275fc00fde28852e3072570 /static/js/controllers/auth_controller.js
parente95ed4cc0bbb3a4e6ca5d109a573a0c423bb1dd9 (diff)
front/auth: implement cookie support
Diffstat (limited to 'static/js/controllers/auth_controller.js')
-rw-r--r--static/js/controllers/auth_controller.js35
1 files changed, 24 insertions, 11 deletions
diff --git a/static/js/controllers/auth_controller.js b/static/js/controllers/auth_controller.js
index 4bcd6ae..7529136 100644
--- a/static/js/controllers/auth_controller.js
+++ b/static/js/controllers/auth_controller.js
@@ -1,5 +1,6 @@
'use strict';
+const cookies = require('js-cookie');
const page = require('page');
const config = require('../config.js');
@@ -8,32 +9,44 @@ class AuthController {
this.api = api;
this.topNavigationController = topNavigationController;
this.loginView = loginView;
- /* TODO: load from cookies */
+
+ const auth = cookies.getJSON('auth');
+ if (auth && auth.user && auth.password) {
+ this.api.login(auth.user, auth.password).catch(() => {
+ cookies.remove('auth');
+ /* TODO: notify the user what just happened */
+ });
+ }
}
loginRoute() {
this.topNavigationController.activate('login');
this.loginView.render({
- login: (userName, userPassword, doRemember) => {
+ login: (name, password, doRemember) => {
return new Promise((resolve, reject) => {
- this.api.login(userName, userPassword);
- this.api.get('/user/' + userName)
- .then(response => {
+ this.api.login(name, password)
+ .then(() => {
+ const options = {};
if (doRemember) {
- /* TODO: set cookie */
+ options.expires = 365;
}
+ cookies.set(
+ 'auth',
+ {'user': name, 'password': password},
+ options);
resolve();
page('/');
- /* TODO: update top navigation */
- })
- .catch(response => { reject(response.description); });
+ /* TODO: notify top navigation */
+ }).catch(errorMessage => { reject(errorMessage); });
});
}});
}
logoutRoute() {
- this.topNavigationController.activate('logout');
- /* TODO: clear cookie */
+ this.api.logout();
+ cookies.remove('auth');
+ page('/');
+ /* TODO: notify top navigation */
}
}

© 2015 - 2026 Jakob L. Kreuze