예제 #1
0
        public ActionResult Convert(string verticalUrl, ConvertModel convertModel)
        {
            var community = GetCommunity(verticalUrl);

            if (community == null)
            {
                return(RedirectToRoute(Public.Routes.HomeRoutes.Home));
            }
            convertModel.Community = community;

            try
            {
                convertModel.Prepare();
                convertModel.Validate();

                // Find the member.

                var member = _membersQuery.GetMember(convertModel.EmailAddress);
                if (member == null)
                {
                    throw new ValidationErrorsException(new NotFoundValidationError("Account", null));
                }

                // Must be a member of the community and the details must match.

                if (!MatchAccount(member, community, convertModel))
                {
                    throw new ValidationErrorsException(new NotFoundValidationError("Account", null));
                }

                // Create the credentials.

                var credentials = new LoginCredentials
                {
                    LoginId      = convertModel.NewEmailAddress,
                    PasswordHash = LoginCredentials.HashToString(convertModel.Password),
                };
                _memberAccountsCommand.CreateCredentials(member, credentials);

                // Send an email if needed.

                if (!member.IsActivated)
                {
                    _accountVerificationsCommand.SendActivation(member, member.GetPrimaryEmailAddress().Address);
                }

                return(RedirectToRoute(VerticalsRoutes.Converted));
            }
            catch (UserException ex)
            {
                ModelState.AddModelError(ex, new VerticalsErrorHandler());
            }

            return(View(convertModel));
        }