public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus = MembershipService.CreateUser( model.UserName, model.Password, model.Email,
                                                                                    model.FirstName, model.LastName, false);

                if (createStatus == MembershipCreateStatus.Success)
                {

                    return RedirectToAction("Welcome","Home");
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
            return View(model);
        }
Пример #2
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
                    WebSecurity.Login(model.UserName, model.Password);
                    return RedirectToAction("Index", "Home");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
        public ActionResult ModeratorSetup(RegisterModel model)
        {
            if (ModelState.IsValid)
            {

                MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email, model.FirstName, model.LastName, true);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    RoleService.CreateRole("Moderator");
                    RoleService.AddUsersToRoles(new string[] { model.UserName }, new string[] { "Moderator" });
                    FormsService.SignIn(model.UserName, true);
                    return RedirectToAction("Accounts", "Moderator");
                }

                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }
            return View(model);
        }