mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-01-29 02:29:20 +01:00
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
44 lines
1.2 KiB
JavaScript
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;
|
|
}
|
|
}
|
|
}());
|