2016-12-15 03:33:47 +00:00
|
|
|
angular.module('settings', [])
|
2017-03-12 16:24:15 +00:00
|
|
|
.controller('SettingsController', ['$scope', '$state', '$sanitize', 'Authentication', 'UserService', 'Messages',
|
|
|
|
function ($scope, $state, $sanitize, Authentication, UserService, Messages) {
|
2016-12-15 03:33:47 +00:00
|
|
|
$scope.formValues = {
|
|
|
|
currentPassword: '',
|
|
|
|
newPassword: '',
|
|
|
|
confirmPassword: ''
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.updatePassword = function() {
|
|
|
|
$scope.invalidPassword = false;
|
2017-03-12 16:24:15 +00:00
|
|
|
var userID = Authentication.getUserDetails().ID;
|
2016-12-15 03:33:47 +00:00
|
|
|
var currentPassword = $sanitize($scope.formValues.currentPassword);
|
2017-03-12 16:24:15 +00:00
|
|
|
var newPassword = $sanitize($scope.formValues.newPassword);
|
|
|
|
|
|
|
|
UserService.updateUserPassword(userID, currentPassword, newPassword)
|
|
|
|
.then(function success() {
|
|
|
|
Messages.send("Success", "Password successfully updated");
|
|
|
|
$state.reload();
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
if (err.invalidPassword) {
|
2016-12-15 03:33:47 +00:00
|
|
|
$scope.invalidPassword = true;
|
2017-03-12 16:24:15 +00:00
|
|
|
} else {
|
|
|
|
Messages.error("Failure", err, err.msg);
|
2016-12-15 03:33:47 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}]);
|