diff --git a/scripts/SettingsController.js b/scripts/SettingsController.js index 0eef4f6..eeaffce 100644 --- a/scripts/SettingsController.js +++ b/scripts/SettingsController.js @@ -6,28 +6,44 @@ angular.module('flashy.SettingsController', ['ui.router']). $scope.mismatch = false; $scope.unacceptable = false; + $scope.changePassword = function(oldPassword, newPassword, confirmedNewPassword) { console.log('in change password'); - if (newPassword != $scope.confirmedNewPassword) { + + + if ($scope.ChangePasswordForm.newpw.$error.minlength == true) { + + $scope.unacceptable = true; + console.log('unacceptable password'); + return; + } + + if (newPassword != confirmedNewPassword) { $scope.mismatch = true; console.log('mismatch'); return; - } + } else { + + $scope.mismatch = false; + + } + + $http.patch('/api/me/', { 'old_password': oldPassword, 'new_password': newPassword }) .success(function(data) { console.log('password successfully changes'); - Materialize.toast('Your password was successfully changed'); + Materialize.toast('Your password was successfully changed', 3000); $state.go('login'); + }) .error(function(data) { console.log('problem changing the password'); - Materialize.toast('Your old password is not correct'); - $state.go('login'); + Materialize.toast('Your old password is not correct', 3000); }); }; diff --git a/templates/settings.html b/templates/settings.html index f006d06..365a749 100644 --- a/templates/settings.html +++ b/templates/settings.html @@ -22,7 +22,7 @@
- +
@@ -37,7 +37,7 @@
- + New password must be at least 8 characters.
@@ -53,10 +53,11 @@ Passwords do not match! - - Submit + + +