diff options
| author | rr- | 2016-04-06 17:56:34 +0200 |
|---|---|---|
| committer | rr- | 2016-04-06 17:56:34 +0200 |
| commit | 92dd958866e021b05a828b0d8c86e613af23dc99 (patch) | |
| tree | d9f6dd4323c1a0f1de582024d3930ddbe39ed58a /client/js/controllers/auth_controller.js | |
| parent | 1fb2f5391467aab77918e302af20b2e8fda0705f (diff) | |
client+server: finish password reminders
Diffstat (limited to 'client/js/controllers/auth_controller.js')
| -rw-r--r-- | client/js/controllers/auth_controller.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/client/js/controllers/auth_controller.js b/client/js/controllers/auth_controller.js index 607a21c..1a4565d 100644 --- a/client/js/controllers/auth_controller.js +++ b/client/js/controllers/auth_controller.js @@ -5,10 +5,12 @@ const page = require('page'); const api = require('../api.js'); const topNavController = require('../controllers/top_nav_controller.js'); const LoginView = require('../views/login_view.js'); +const PasswordResetView = require('../views/password_reset_view.js'); class AuthController { constructor() { this.loginView = new LoginView(); + this.passwordResetView = new PasswordResetView(); const auth = cookies.getJSON('auth'); if (auth && auth.user && auth.password) { @@ -51,6 +53,43 @@ class AuthController { page('/'); this.loginView.notifySuccess('Logged out'); } + + passwordResetRoute() { + topNavController.activate('login'); + this.passwordResetView.render({ + proceed: nameOrEmail => { + api.logout(); + cookies.remove('auth'); + return new Promise((resolve, reject) => { + api.get('/password-reset/' + nameOrEmail) + .then(() => { resolve(); }) + .catch(errorMessage => { reject(errorMessage); }); + }); + }}); + } + + passwordResetFinishRoute(name, token) { + api.logout(); + cookies.remove('auth'); + api.post('/password-reset/' + name, {token: token}) + .then(response => { + const password = response.password; + api.login(name, password) + .then(() => { + cookies.set( + 'auth', {'user': name, 'password': password}, {}); + page('/'); + this.passwordResetView.notifySuccess( + 'New password: ' + password); + }).catch(errorMessage => { + page('/'); + this.passwordResetView.notifyError(errorMessage); + }); + }).catch(response => { + page('/'); + this.passwordResetView.notifyError(response.description); + }); + } } module.exports = new AuthController(); |