Exemplo n.º 1
0
        public async Task <ActionResult> ForgottenEmail(ForgottenCredentialsViewModel model)
        {
            return(await Task.Run <ActionResult>(() =>
            {
                var response = _loginMediator.ForgottenEmail(model);

                ModelState.Clear();

                switch (response.Code)
                {
                case LoginMediatorCodes.ForgottenEmail.FailedValidation:
                    response.ValidationResult.AddToModelState(ModelState, string.Empty);
                    return View(RouteNames.ForgottenCredentials, response.ViewModel);

                case LoginMediatorCodes.ForgottenEmail.FailedToSendEmail:
                    SetUserMessage(response.Message.Text, response.Message.Level);
                    return RedirectToRoute(RouteNames.SignIn);

                case LoginMediatorCodes.ForgottenEmail.EmailSent:
                    SetUserMessage(response.Message.Text, response.Message.Level);
                    return RedirectToRoute(RouteNames.SignIn);

                default:
                    throw new InvalidMediatorCodeException(response.Code);
                }
            }));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> ForgottenPassword(ForgottenCredentialsViewModel model)
        {
            return(await Task.Run <ActionResult>(() =>
            {
                var response = _loginMediator.ForgottenPassword(model);

                ModelState.Clear();

                switch (response.Code)
                {
                case LoginMediatorCodes.ForgottenPassword.FailedValidation:
                    response.ValidationResult.AddToModelState(ModelState, string.Empty);
                    return View(RouteNames.ForgottenCredentials, response.ViewModel);

                case LoginMediatorCodes.ForgottenPassword.FailedToSendResetCode:
                    SetUserMessage(response.Message.Text, response.Message.Level);
                    return View(RouteNames.ForgottenCredentials, response.ViewModel);

                case LoginMediatorCodes.ForgottenPassword.PasswordSent:
                    UserData.Push(UserDataItemNames.EmailAddress, model.ForgottenPasswordViewModel.EmailAddress);
                    return RedirectToRoute(RouteNames.ResetPassword);

                default:
                    throw new InvalidMediatorCodeException(response.Code);
                }
            }));
        }
Exemplo n.º 3
0
        public void FailedToSendEmail()
        {
            const string phoneNumber = "0123456789";

            var viewModel = new ForgottenCredentialsViewModel
            {
                ForgottenEmailViewModel = new ForgottenEmailViewModel
                {
                    PhoneNumber = phoneNumber
                }
            };

            var candidateServiceProvider = new Mock <ICandidateServiceProvider>();

            candidateServiceProvider.Setup(csp => csp.RequestEmailReminder(It.IsAny <ForgottenEmailViewModel>()))
            .Returns(false);
            var mediator = new LoginMediatorBuilder().With(candidateServiceProvider).Build();

            var response = mediator.ForgottenEmail(viewModel);

            var message = string.Format(LoginPageMessages.ForgottenEmailSent, phoneNumber);

            response.AssertMessage(LoginMediatorCodes.ForgottenEmail.FailedToSendEmail, message,
                                   UserMessageLevel.Success, true);
        }
Exemplo n.º 4
0
        public MediatorResponse <ForgottenCredentialsViewModel> ForgottenPassword(ForgottenCredentialsViewModel forgottenCredentialsViewModel)
        {
            var forgottenPasswordViewModel = forgottenCredentialsViewModel.ForgottenPasswordViewModel;
            var validationResult           = _forgottenPasswordViewModelServerValidator.Validate(forgottenPasswordViewModel);

            if (!validationResult.IsValid)
            {
                return(GetMediatorResponse(LoginMediatorCodes.ForgottenPassword.FailedValidation, forgottenCredentialsViewModel, validationResult));
            }

            if (_candidateServiceProvider.RequestForgottenPasswordResetCode(forgottenPasswordViewModel))
            {
                return(GetMediatorResponse(LoginMediatorCodes.ForgottenPassword.PasswordSent, forgottenCredentialsViewModel));
            }

            return(GetMediatorResponse(LoginMediatorCodes.ForgottenPassword.FailedToSendResetCode, forgottenCredentialsViewModel, PasswordResetPageMessages.FailedToSendPasswordResetCode, UserMessageLevel.Warning));
        }
Exemplo n.º 5
0
        public void FailedValidation()
        {
            const string phoneNumber = "NotANumber";

            var viewModel = new ForgottenCredentialsViewModel
            {
                ForgottenEmailViewModel = new ForgottenEmailViewModel
                {
                    PhoneNumber = phoneNumber
                }
            };

            var mediator = new LoginMediatorBuilder().Build();

            var response = mediator.ForgottenEmail(viewModel);

            response.AssertValidationResult(LoginMediatorCodes.ForgottenEmail.FailedValidation);
        }
Exemplo n.º 6
0
        public MediatorResponse <ForgottenCredentialsViewModel> ForgottenEmail(ForgottenCredentialsViewModel forgottenCredentialsViewModel)
        {
            var forgottenEmailViewModel = forgottenCredentialsViewModel.ForgottenEmailViewModel;
            var validationResult        = _forgottenEmailViewModelServerValidator.Validate(forgottenEmailViewModel);

            if (!validationResult.IsValid)
            {
                return(GetMediatorResponse(LoginMediatorCodes.ForgottenEmail.FailedValidation, forgottenCredentialsViewModel, validationResult));
            }

            var message = string.Format(LoginPageMessages.ForgottenEmailSent, forgottenEmailViewModel.PhoneNumber);

            if (_candidateServiceProvider.RequestEmailReminder(forgottenEmailViewModel))
            {
                return(GetMediatorResponse(LoginMediatorCodes.ForgottenEmail.EmailSent, forgottenCredentialsViewModel, message, UserMessageLevel.Success));
            }

            return(GetMediatorResponse(LoginMediatorCodes.ForgottenEmail.FailedToSendEmail, forgottenCredentialsViewModel, message, UserMessageLevel.Success));
        }