diff options
| author | rr- | 2016-04-01 18:45:25 +0200 |
|---|---|---|
| committer | rr- | 2016-04-01 18:48:16 +0200 |
| commit | e487adcc97b8d2bd111a34b7d3c72d66001deb8b (patch) | |
| tree | d684abf99bf176ead0a785bc237ae3b6a81417c1 /static/js/controllers/auth_controller.js | |
| parent | 1ad71585c4e95555566e8af068d5addf75b33274 (diff) | |
split files into client/ and server/
Diffstat (limited to 'static/js/controllers/auth_controller.js')
| -rw-r--r-- | static/js/controllers/auth_controller.js | 56 |
1 files changed, 0 insertions, 56 deletions
diff --git a/static/js/controllers/auth_controller.js b/static/js/controllers/auth_controller.js deleted file mode 100644 index 39a0c43..0000000 --- a/static/js/controllers/auth_controller.js +++ /dev/null @@ -1,56 +0,0 @@ -'use strict'; - -const cookies = require('js-cookie'); -const page = require('page'); -const api = require('../api.js'); -const topNavController = require('../controllers/top_nav_controller.js'); -const LoginView = require('../views/login_view.js'); - -class AuthController { - constructor() { - this.loginView = new LoginView(); - - const auth = cookies.getJSON('auth'); - if (auth && auth.user && auth.password) { - api.login(auth.user, auth.password).catch(errorMessage => { - cookies.remove('auth'); - page('/'); - this.loginView.notifyError( - 'An error happened while trying to log you in: ' + - errorMessage); - }); - } - } - - loginRoute() { - topNavController.activate('login'); - this.loginView.render({ - login: (name, password, doRemember) => { - return new Promise((resolve, reject) => { - api.login(name, password) - .then(() => { - const options = {}; - if (doRemember) { - options.expires = 365; - } - cookies.set( - 'auth', - {'user': name, 'password': password}, - options); - resolve(); - page('/'); - this.loginView.notifySuccess('Logged in'); - }).catch(errorMessage => { reject(errorMessage); }); - }); - }}); - } - - logoutRoute() { - api.logout(); - cookies.remove('auth'); - page('/'); - this.loginView.notifySuccess('Logged out'); - } -} - -module.exports = new AuthController(); |