Files
meanTorrent/modules/users/client/controllers/settings/change-password.client.controller.js
Michael Leanos fa138045e6 Deprecated $http success/error promise methods (#1508)
Replaces the $http service calls with promise based methods
of the client-side UsersService for the following:
  Users Change Password
  Users Manage Social Accounts
  Users Password Forgot
  Users Password Reset
  Users Signup
  Users Signin

Modifies tests to reflect changes.

Closes #1479
2016-09-17 12:05:21 -07:00

44 lines
1.2 KiB
JavaScript

(function () {
'use strict';
angular
.module('users')
.controller('ChangePasswordController', ChangePasswordController);
ChangePasswordController.$inject = ['$scope', '$http', 'Authentication', 'UsersService', 'PasswordValidator'];
function ChangePasswordController($scope, $http, Authentication, UsersService, PasswordValidator) {
var vm = this;
vm.user = Authentication.user;
vm.changeUserPassword = changeUserPassword;
vm.getPopoverMsg = PasswordValidator.getPopoverMsg;
// Change user password
function changeUserPassword(isValid) {
vm.success = vm.error = null;
if (!isValid) {
$scope.$broadcast('show-errors-check-validity', 'vm.passwordForm');
return false;
}
UsersService.changePassword(vm.passwordDetails)
.then(onChangePasswordSuccess)
.catch(onChangePasswordError);
}
function onChangePasswordSuccess(response) {
// If successful show success message and clear form
$scope.$broadcast('show-errors-reset', 'vm.passwordForm');
vm.success = true;
vm.passwordDetails = null;
}
function onChangePasswordError(response) {
vm.error = response.data.message;
}
}
}());