2016-02-11 22:34:20 -03:00
|
|
|
(function () {
|
|
|
|
|
'use strict';
|
2014-11-10 23:12:33 +02:00
|
|
|
|
2016-02-11 22:34:20 -03:00
|
|
|
angular
|
|
|
|
|
.module('users')
|
|
|
|
|
.controller('ChangePasswordController', ChangePasswordController);
|
|
|
|
|
|
2016-10-10 17:51:44 -04:00
|
|
|
ChangePasswordController.$inject = ['$scope', '$http', 'Authentication', 'UsersService', 'PasswordValidator', 'Notification'];
|
2016-02-11 22:34:20 -03:00
|
|
|
|
2016-10-10 17:51:44 -04:00
|
|
|
function ChangePasswordController($scope, $http, Authentication, UsersService, PasswordValidator, Notification) {
|
2016-02-11 22:34:20 -03:00
|
|
|
var vm = this;
|
|
|
|
|
|
|
|
|
|
vm.user = Authentication.user;
|
|
|
|
|
vm.changeUserPassword = changeUserPassword;
|
|
|
|
|
vm.getPopoverMsg = PasswordValidator.getPopoverMsg;
|
2014-11-10 23:12:33 +02:00
|
|
|
|
2015-07-25 16:53:11 -04:00
|
|
|
// Change user password
|
2016-02-11 22:34:20 -03:00
|
|
|
function changeUserPassword(isValid) {
|
2014-11-10 23:12:33 +02:00
|
|
|
|
2015-08-05 00:40:54 -04:00
|
|
|
if (!isValid) {
|
2016-02-11 22:34:20 -03:00
|
|
|
$scope.$broadcast('show-errors-check-validity', 'vm.passwordForm');
|
2015-08-05 00:40:54 -04:00
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-17 12:05:21 -07:00
|
|
|
UsersService.changePassword(vm.passwordDetails)
|
|
|
|
|
.then(onChangePasswordSuccess)
|
|
|
|
|
.catch(onChangePasswordError);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onChangePasswordSuccess(response) {
|
|
|
|
|
// If successful show success message and clear form
|
2016-10-10 17:51:44 -04:00
|
|
|
Notification.success({ message: '<i class="glyphicon glyphicon-ok"></i> Password Changed Successfully' });
|
2016-09-17 12:05:21 -07:00
|
|
|
vm.passwordDetails = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onChangePasswordError(response) {
|
2016-10-10 17:51:44 -04:00
|
|
|
Notification.error({ message: response.data.message, title: '<i class="glyphicon glyphicon-remove"></i> Password change failed!' });
|
2016-02-11 22:34:20 -03:00
|
|
|
}
|
2015-07-25 16:53:11 -04:00
|
|
|
}
|
2015-12-10 20:31:51 +01:00
|
|
|
}());
|