diff --git a/static/js/api.js b/static/js/api.js index 0c86177c..b950b688 100644 --- a/static/js/api.js +++ b/static/js/api.js @@ -78,6 +78,7 @@ class Api { } logout() { + this.user = null; this.userName = null; this.userPassword = null; this.authenticated.fire(); diff --git a/static/js/controllers/users_controller.js b/static/js/controllers/users_controller.js index 3872d3f0..5bd78f8d 100644 --- a/static/js/controllers/users_controller.js +++ b/static/js/controllers/users_controller.js @@ -1,5 +1,6 @@ 'use strict'; +const cookies = require('js-cookie'); const page = require('page'); const api = require('../api.js'); const topNavController = require('../controllers/top_nav_controller.js'); @@ -16,7 +17,9 @@ class UsersController { createUserRoute() { topNavController.activate('register'); - this.registrationView.render({register: this._register}); + this.registrationView.render({register: (...args) => { + return this._register(...args); + }}); } _register(name, password, email) { @@ -29,8 +32,10 @@ class UsersController { return new Promise((resolve, reject) => { api.post('/users/', data).then(() => { api.login(name, password).then(() => { + cookies.set('auth', {'user': name, 'password': password}); resolve(); page('/'); + this.registrationView.notifySuccess('Welcome aboard!'); }).catch(response => { reject(response.description); }); @@ -41,8 +46,7 @@ class UsersController { } showUserRoute(user) { - if (api.isLoggedIn() && - user == api.getCurrentUser().name) { + if (api.isLoggedIn() && user == api.userName) { topNavController.activate('account'); } else { topNavController.activate('users');