diff --git a/client/js/controllers/auth_controller.js b/client/js/controllers/auth_controller.js index 08a4a0d5..80e32dcd 100644 --- a/client/js/controllers/auth_controller.js +++ b/client/js/controllers/auth_controller.js @@ -33,7 +33,10 @@ class AuthController { resolve(); page('/'); events.notify(events.Success, 'Logged in'); - }).catch(errorMessage => { reject(errorMessage); }); + }).catch(errorMessage => { + reject(errorMessage); + events.notify(events.Error, errorMessage); + }); }); }}); } @@ -47,13 +50,8 @@ class AuthController { passwordResetRoute() { topNavController.activate('login'); this.passwordResetView.render({ - proceed: nameOrEmail => { - api.logout(); - return new Promise((resolve, reject) => { - api.get('/password-reset/' + nameOrEmail) - .then(() => { resolve(); }) - .catch(errorMessage => { reject(errorMessage); }); - }); + proceed: (...args) => { + return this._passwordReset(...args); }}); } @@ -76,6 +74,23 @@ class AuthController { events.notify(events.Error, response.description); }); } + + _passwordReset(nameOrEmail) { + api.logout(); + return new Promise((resolve, reject) => { + api.get('/password-reset/' + nameOrEmail) + .then(() => { + resolve(); + events.notify( + events.Success, + 'E-mail has been sent. To finish the procedure, ' + + 'please click the link it contains.'); + }).catch(response => { + reject(); + events.notify(events.Error, response.description); + }); + }); + } } module.exports = new AuthController(); diff --git a/client/js/controllers/users_controller.js b/client/js/controllers/users_controller.js index 8b84d18c..fe42a878 100644 --- a/client/js/controllers/users_controller.js +++ b/client/js/controllers/users_controller.js @@ -72,11 +72,13 @@ class UsersController { resolve(); page('/'); events.notify(events.Success, 'Welcome aboard!'); - }).catch(response => { - reject(response.description); + }).catch(errorMessage => { + reject(); + events.notify(events.Error, errorMessage); }); }).catch(response => { - reject(response.description); + reject(); + events.notify(events.Error, response.description); }); }); } @@ -103,10 +105,9 @@ class UsersController { newPassword || api.userPassword, false) .then(next) - .catch(response => { + .catch(errorMessage => { reject(); - events.notify( - events.Error, response.description); + events.notify(events.Error, errorMessage); }); } else { next(); diff --git a/client/js/util/polyfill.js b/client/js/util/polyfill.js index 939e62c3..a6a7db78 100644 --- a/client/js/util/polyfill.js +++ b/client/js/util/polyfill.js @@ -27,3 +27,13 @@ if (!Object.entries) { // fix iterating over NodeList in Chrome and Opera NodeList.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator]; + +// non standard +Promise.prototype.always = function(onResolveOrReject) { + return this.then( + onResolveOrReject, + reason => { + onResolveOrReject(reason); + throw reason; + }); +}; diff --git a/client/js/views/login_view.js b/client/js/views/login_view.js index e7574160..f8b82a20 100644 --- a/client/js/views/login_view.js +++ b/client/js/views/login_view.js @@ -31,13 +31,7 @@ class LoginView extends BaseView { userNameField.value, passwordField.value, rememberUserField.checked) - .then(() => { - this.enableForm(form); - }) - .catch(errorMessage => { - this.enableForm(form); - events.notify(events.Error, errorMessage); - }); + .always(() => { this.enableForm(form); }); }); this.showView(target, source); diff --git a/client/js/views/password_reset_view.js b/client/js/views/password_reset_view.js index 389b29d4..12729bc9 100644 --- a/client/js/views/password_reset_view.js +++ b/client/js/views/password_reset_view.js @@ -23,16 +23,7 @@ class PasswordResetView extends BaseView { this.clearMessages(); this.disableForm(form); ctx.proceed(userNameOrEmailField.value) - .then(() => { - events.notify( - events.Success, - 'E-mail has been sent. To finish the procedure, ' + - 'please click the link it contains.'); - }) - .catch(errorMessage => { - this.enableForm(form); - events.notify(events.Error, errorMessage); - }); + .catch(() => { this.enableForm(form); }); }); this.showView(target, source); diff --git a/client/js/views/registration_view.js b/client/js/views/registration_view.js index 77511e16..7c58ab51 100644 --- a/client/js/views/registration_view.js +++ b/client/js/views/registration_view.js @@ -31,13 +31,7 @@ class RegistrationView extends BaseView { userNameField.value, passwordField.value, emailField.value) - .then(() => { - this.enableForm(form); - }) - .catch(errorMessage => { - this.enableForm(form); - events.notify(events.Error, errorMessage); - }); + .always(() => { this.enableForm(form); }); }); this.showView(target, source); diff --git a/client/js/views/user_edit_view.js b/client/js/views/user_edit_view.js index 07d6e0d0..9d5c3ae1 100644 --- a/client/js/views/user_edit_view.js +++ b/client/js/views/user_edit_view.js @@ -48,8 +48,7 @@ class UserEditView extends BaseView { passwordField.value, emailField.value, rankField.value) - .then(user => { this.enableForm(form); }) - .catch(() => { this.enableForm(form); }); + .always(() => { this.enableForm(form); }); }); this.showView(target, source);