コード例 #1
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                using (var store = new UserStore<IdentityUser>(new IdentityDbContext()))
                {
                    using (var manager = new UserManager<IdentityUser>(store))
                    {
                        var user = new IdentityUser { UserName = model.UserName};
                        var result = manager.Create(user, model.Password);
                        if (result.Succeeded)
                        {
                            Authenticate(manager, user);

                            return RedirectToAction("Index", "Home");
                        }
                        AddErrors(result);
                    };
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
コード例 #2
0
ファイル: AccountController.cs プロジェクト: tavishi/leap14
        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);
        }