2015-06-29 22:51:29 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-06-30 16:19:09 +00:00
|
|
|
angular.module('users').controller('PasswordController', ['$scope', '$stateParams', '$state', 'Principal',
|
|
|
|
function($scope, $stateParams, $state, Principal) {
|
2015-06-29 22:51:29 +00:00
|
|
|
$scope.authentication = Principal;
|
|
|
|
|
|
|
|
//If user is signed in then redirect back home
|
2015-06-30 16:30:56 +00:00
|
|
|
if ($scope.authentication.isAuthenticated()) $state.go('home');
|
|
|
|
|
|
|
|
Principal.identity().then(function(response){
|
|
|
|
$scope.authentication.user = response;
|
|
|
|
|
|
|
|
// Submit forgotten password account id
|
|
|
|
$scope.askForPasswordReset = function() {
|
|
|
|
Principal.askForPasswordReset($scope.credentials).then(
|
|
|
|
function(response){
|
|
|
|
$scope.success = response.message
|
|
|
|
$scope.credentials = null;
|
|
|
|
},
|
|
|
|
function(error){
|
|
|
|
$scope.error = error;
|
|
|
|
$scope.credentials = null;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Change user password
|
|
|
|
$scope.resetUserPassword = function() {
|
|
|
|
Principal.askForPasswordReset($scope.credentials).then(
|
|
|
|
function(response){
|
|
|
|
$scope.credentials = null;
|
|
|
|
},
|
|
|
|
function(error){
|
|
|
|
$scope.error = error;
|
|
|
|
$scope.credentials = null;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
// $scope.success = $scope.error = null;
|
|
|
|
|
|
|
|
// $http.post('/auth/reset/' + $stateParams.token, $scope.passwordDetails).success(function(response) {
|
|
|
|
// // If successful show success message and clear form
|
|
|
|
// $scope.passwordDetails = null;
|
|
|
|
|
|
|
|
// // Attach user profile
|
|
|
|
// // Principal.user() = response;
|
|
|
|
|
|
|
|
// // And redirect to the index page
|
|
|
|
// $state.go('reset-success');
|
|
|
|
// }).error(function(response) {
|
|
|
|
// $scope.error = response.message;
|
|
|
|
// });
|
|
|
|
};
|
|
|
|
});
|
2015-06-29 22:51:29 +00:00
|
|
|
}
|
|
|
|
]);
|