2014-11-10 23:12:33 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
2015-09-02 23:21:24 -04:00
|
|
|
angular.module('users').controller('ChangePasswordController', ['$scope', '$http', 'Authentication', 'PasswordValidator',
|
|
|
|
|
function ($scope, $http, Authentication, PasswordValidator) {
|
2015-07-25 16:53:11 -04:00
|
|
|
$scope.user = Authentication.user;
|
2015-09-02 23:21:24 -04:00
|
|
|
$scope.popoverMsg = PasswordValidator.getPopoverMsg();
|
2014-11-10 23:12:33 +02:00
|
|
|
|
2015-07-25 16:53:11 -04:00
|
|
|
// Change user password
|
2015-08-05 00:40:54 -04:00
|
|
|
$scope.changeUserPassword = function (isValid) {
|
2015-07-25 16:53:11 -04:00
|
|
|
$scope.success = $scope.error = null;
|
2014-11-10 23:12:33 +02:00
|
|
|
|
2015-08-05 00:40:54 -04:00
|
|
|
if (!isValid) {
|
|
|
|
|
$scope.$broadcast('show-errors-check-validity', 'passwordForm');
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-25 16:53:11 -04:00
|
|
|
$http.post('/api/users/password', $scope.passwordDetails).success(function (response) {
|
|
|
|
|
// If successful show success message and clear form
|
2015-08-05 00:40:54 -04:00
|
|
|
$scope.$broadcast('show-errors-reset', 'passwordForm');
|
2015-07-25 16:53:11 -04:00
|
|
|
$scope.success = true;
|
|
|
|
|
$scope.passwordDetails = null;
|
|
|
|
|
}).error(function (response) {
|
|
|
|
|
$scope.error = response.message;
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
}
|
2014-11-10 23:12:33 +02:00
|
|
|
]);
|