Files
meanTorrent/modules/users/client/controllers/password.client.controller.js
Ryan Hutchison ef3a3f9548 formatting reboot (space-2 and consistency)
JSCS fixes

update editorconfig
2015-07-31 10:04:02 -04:00

47 lines
1.5 KiB
JavaScript

'use strict';
angular.module('users').controller('PasswordController', ['$scope', '$stateParams', '$http', '$location', 'Authentication',
function ($scope, $stateParams, $http, $location, Authentication) {
$scope.authentication = Authentication;
//If user is signed in then redirect back home
if ($scope.authentication.user) {
$location.path('/');
}
// Submit forgotten password account id
$scope.askForPasswordReset = function () {
$scope.success = $scope.error = null;
$http.post('/api/auth/forgot', $scope.credentials).success(function (response) {
// Show user success message and clear form
$scope.credentials = null;
$scope.success = response.message;
}).error(function (response) {
// Show user error message and clear form
$scope.credentials = null;
$scope.error = response.message;
});
};
// Change user password
$scope.resetUserPassword = function () {
$scope.success = $scope.error = null;
$http.post('/api/auth/reset/' + $stateParams.token, $scope.passwordDetails).success(function (response) {
// If successful show success message and clear form
$scope.passwordDetails = null;
// Attach user profile
Authentication.user = response;
// And redirect to the index page
$location.path('/password/reset/success');
}).error(function (response) {
$scope.error = response.message;
});
};
}
]);