Example #1
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    WebSecurity.CreateUserAndAccount(model.UserName, model.Password);

                    UserContext user = new UserContext()
                    {
                        Id = ObjectId.GenerateNewId().ToString(), Email = model.Email, Login = model.UserName
                    };
                    context.AddUser(user);
                    WebSecurity.Login(model.UserName, model.Password);
                    return(RedirectToAction("Index", "Home"));
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", "Ошибка создания пользователя");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }