Exemplo n.º 1
0
        public ActionResult Verification(string verificationCode)
        {
            string loginId = null;

            try
            {
                if (string.IsNullOrEmpty(verificationCode))
                {
                    ModelState.AddModelError(new RequiredValidationError("verificationCode"), new ActivationErrorHandler());
                    return(View(new ActivationModel {
                        Login = new Login()
                    }));
                }

                // Activate.

                var memberId = _accountVerificationsCommand.Verify(verificationCode);
                if (memberId == null)
                {
                    ModelState.AddModelError(new NotFoundValidationError("verificationCode", verificationCode), new ActivationErrorHandler());
                    return(View(new ActivationModel {
                        Login = new Login()
                    }));
                }

                // Checked whether logged in.

                var currentUser = CurrentRegisteredUser;
                if (currentUser == null)
                {
                    loginId = GetLoginId(memberId.Value);
                }
                else
                {
                    if (currentUser.Id == memberId)
                    {
                        // Update the user.

                        _authenticationManager.UpdateUser(HttpContext, currentUser, true);
                        return(RedirectToUrl(GetLoggedInMemberUrl(currentUser)));
                    }
                }

                ModelState.AddModelConfirmation("Your email address is now verified, please log in.");
            }
            catch (UserException ex)
            {
                ModelState.AddModelError(ex, new ActivationErrorHandler());
            }

            return(View(new ActivationModel {
                Login = new Login {
                    LoginId = loginId
                }
            }));
        }