public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new User();

                user.InjectFrom<UnflatLoopValueInjection>(model);
                user.ShowWelcomePage = true;

                CreateUserStatus createStatus = _userService.CreateUser(user);

                if (createStatus == CreateUserStatus.Success)
                {
                    _messageBus.Publish(new UserCreated(user, Url.AbsoluteAction("Login", "Account")));

                    if (_membershipSetings.RequireAccountVerification)
                    {
                        new Mailer().VerifyAccount(new VerifyAccountModel());

                        // I don't like this
                        // should be return RedirectToAction
                        return View("Success", model);
                    }
                    if (_membershipSetings.AllowLoginAfterAccountCreation)
                    {
                        _authenticationService.SignIn(user, true);
                        TempData.AddSuccessMessage("Welcome to your new account, " + user.Username + "!");
                        return RedirectToAction("Index", "Home");
                    }
                    return View("Confirm", true);
                }

                ModelState.AddModelError(string.Empty, createStatus.GetDescription());
            }

            return View(model);
        }
Ejemplo n.º 2
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            ViewBag.PasswordLength = MembershipService.MinPasswordLength;
            return View(model);
        }