2014-07-31 11:27:14 +03:00
|
|
|
'use strict';
|
|
|
|
|
|
2015-09-02 23:21:24 -04:00
|
|
|
angular.module('users').controller('PasswordController', ['$scope', '$stateParams', '$http', '$location', 'Authentication', 'PasswordValidator',
|
|
|
|
|
function ($scope, $stateParams, $http, $location, Authentication, PasswordValidator) {
|
2015-07-25 16:53:11 -04:00
|
|
|
$scope.authentication = Authentication;
|
2015-09-02 23:21:24 -04:00
|
|
|
$scope.popoverMsg = PasswordValidator.getPopoverMsg();
|
2015-07-25 16:53:11 -04:00
|
|
|
|
2016-01-07 22:18:36 +01:00
|
|
|
// If user is signed in then redirect back home
|
2015-07-25 16:53:11 -04:00
|
|
|
if ($scope.authentication.user) {
|
|
|
|
|
$location.path('/');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Submit forgotten password account id
|
2015-09-02 23:21:24 -04:00
|
|
|
$scope.askForPasswordReset = function (isValid) {
|
2015-07-25 16:53:11 -04:00
|
|
|
$scope.success = $scope.error = null;
|
|
|
|
|
|
2015-09-02 23:21:24 -04:00
|
|
|
if (!isValid) {
|
|
|
|
|
$scope.$broadcast('show-errors-check-validity', 'forgotPasswordForm');
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-25 16:53:11 -04:00
|
|
|
$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
|
2015-09-02 23:21:24 -04:00
|
|
|
$scope.resetUserPassword = function (isValid) {
|
2015-07-25 16:53:11 -04:00
|
|
|
$scope.success = $scope.error = null;
|
|
|
|
|
|
2015-09-02 23:21:24 -04:00
|
|
|
if (!isValid) {
|
|
|
|
|
$scope.$broadcast('show-errors-check-validity', 'resetPasswordForm');
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-25 16:53:11 -04:00
|
|
|
$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;
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
}
|
2015-02-16 21:35:33 +01:00
|
|
|
]);
|