Esempio n. 1
0
        public MediatorResponse <PasswordResetViewModel> ResetPassword(PasswordResetViewModel resetViewModel)
        {
            //Password Reset Code is verified in VerifyPasswordReset.
            //Initially assume the reset code is valid as a full check requires hitting the repo.
            resetViewModel.IsPasswordResetCodeValid = true;

            var validationResult = _passwordResetViewModelServerValidator.Validate(resetViewModel);

            if (!validationResult.IsValid)
            {
                return(GetMediatorResponse(RegisterMediatorCodes.ResetPassword.FailedValidation, resetViewModel, validationResult));
            }

            resetViewModel = _candidateServiceProvider.VerifyPasswordReset(resetViewModel);

            if (resetViewModel.HasError())
            {
                return(GetMediatorResponse(RegisterMediatorCodes.ResetPassword.FailedToResetPassword, resetViewModel, resetViewModel.ViewModelMessage, UserMessageLevel.Warning));
            }

            if (resetViewModel.UserStatus == UserStatuses.Locked)
            {
                return(GetMediatorResponse(RegisterMediatorCodes.ResetPassword.UserAccountLocked, resetViewModel));
            }

            if (!resetViewModel.IsPasswordResetCodeValid)
            {
                validationResult = _passwordResetViewModelServerValidator.Validate(resetViewModel);
                return(GetMediatorResponse(RegisterMediatorCodes.ResetPassword.InvalidResetCode, resetViewModel, validationResult));
            }

            return(GetMediatorResponse(RegisterMediatorCodes.ResetPassword.SuccessfullyResetPassword, resetViewModel, PasswordResetPageMessages.SuccessfulPasswordReset, UserMessageLevel.Success));
        }
Esempio n. 2
0
        public MediatorResponse <PasswordResetViewModel> ResetPassword(PasswordResetViewModel resetViewModel)
        {
            //Password Reset Code is verified in VerifyPasswordReset.
            //Initially assume the reset code is valid as a full check requires hitting the repo.
            resetViewModel.IsPasswordResetCodeValid = true;

            var validationResult = _passwordResetViewModelServerValidator.Validate(resetViewModel);

            if (!validationResult.IsValid)
            {
                return(GetMediatorResponse(LoginMediatorCodes.ResetPassword.FailedValidation, resetViewModel, validationResult));
            }

            resetViewModel = _candidateServiceProvider.VerifyPasswordReset(resetViewModel);

            if (resetViewModel.HasError())
            {
                return(GetMediatorResponse(LoginMediatorCodes.ResetPassword.FailedToResetPassword, resetViewModel, resetViewModel.ViewModelMessage, UserMessageLevel.Warning));
            }

            if (resetViewModel.UserStatus == UserStatuses.Locked)
            {
                return(GetMediatorResponse(LoginMediatorCodes.ResetPassword.UserAccountLocked, resetViewModel));
            }

            if (!resetViewModel.IsPasswordResetCodeValid)
            {
                validationResult = _passwordResetViewModelServerValidator.Validate(resetViewModel);
                return(GetMediatorResponse(LoginMediatorCodes.ResetPassword.InvalidResetCode, resetViewModel, validationResult));
            }

            var candidate = _candidateServiceProvider.GetCandidate(resetViewModel.EmailAddress);

            SetUsersApplicationContext(candidate.EntityId);
            _authenticationTicketService.SetAuthenticationCookie(candidate.EntityId.ToString(), UserRoleNames.Activated);

            return(GetMediatorResponse(LoginMediatorCodes.ResetPassword.SuccessfullyResetPassword, resetViewModel, PasswordResetPageMessages.SuccessfulPasswordReset, UserMessageLevel.Success));
        }