mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-01-15 03:42:23 +01:00
Added visual notification for user/article updates angular-ui-notification config added to core client config Notification idea from #369
81 lines
2.7 KiB
JavaScript
81 lines
2.7 KiB
JavaScript
(function () {
|
|
'use strict';
|
|
|
|
angular
|
|
.module('users')
|
|
.controller('PasswordController', PasswordController);
|
|
|
|
PasswordController.$inject = ['$scope', '$stateParams', 'UsersService', '$location', 'Authentication', 'PasswordValidator', 'Notification'];
|
|
|
|
function PasswordController($scope, $stateParams, UsersService, $location, Authentication, PasswordValidator, Notification) {
|
|
var vm = this;
|
|
|
|
vm.resetUserPassword = resetUserPassword;
|
|
vm.askForPasswordReset = askForPasswordReset;
|
|
vm.authentication = Authentication;
|
|
vm.getPopoverMsg = PasswordValidator.getPopoverMsg;
|
|
|
|
// If user is signed in then redirect back home
|
|
if (vm.authentication.user) {
|
|
$location.path('/');
|
|
}
|
|
|
|
// Submit forgotten password account id
|
|
function askForPasswordReset(isValid) {
|
|
|
|
if (!isValid) {
|
|
$scope.$broadcast('show-errors-check-validity', 'vm.forgotPasswordForm');
|
|
|
|
return false;
|
|
}
|
|
|
|
UsersService.requestPasswordReset(vm.credentials)
|
|
.then(onRequestPasswordResetSuccess)
|
|
.catch(onRequestPasswordResetError);
|
|
}
|
|
|
|
// Change user password
|
|
function resetUserPassword(isValid) {
|
|
|
|
if (!isValid) {
|
|
$scope.$broadcast('show-errors-check-validity', 'vm.resetPasswordForm');
|
|
|
|
return false;
|
|
}
|
|
|
|
UsersService.resetPassword($stateParams.token, vm.passwordDetails)
|
|
.then(onResetPasswordSuccess)
|
|
.catch(onResetPasswordError);
|
|
}
|
|
|
|
// Password Reset Callbacks
|
|
|
|
function onRequestPasswordResetSuccess(response) {
|
|
// Show user success message and clear form
|
|
vm.credentials = null;
|
|
Notification.success({ message: response.message, title: '<i class="glyphicon glyphicon-ok"></i> Password reset email sent successfully!' });
|
|
}
|
|
|
|
function onRequestPasswordResetError(response) {
|
|
// Show user error message and clear form
|
|
vm.credentials = null;
|
|
Notification.error({ message: response.data.message, title: '<i class="glyphicon glyphicon-remove"></i> Failed to send password reset email!', delay: 4000 });
|
|
}
|
|
|
|
function onResetPasswordSuccess(response) {
|
|
// If successful show success message and clear form
|
|
vm.passwordDetails = null;
|
|
|
|
// Attach user profile
|
|
Authentication.user = response;
|
|
Notification.success({ message: '<i class="glyphicon glyphicon-ok"></i> Password reset successful!' });
|
|
// And redirect to the index page
|
|
$location.path('/password/reset/success');
|
|
}
|
|
|
|
function onResetPasswordError(response) {
|
|
Notification.error({ message: response.data.message, title: '<i class="glyphicon glyphicon-remove"></i> Password reset failed!', delay: 4000 });
|
|
}
|
|
}
|
|
}());
|