コード例 #1
0
        public ActionResult Login(AuthenticationViewModel model, string returnUrl)
        {
            PersonMembershipProvider memberShip = new PersonMembershipProvider();

            if (ModelState.IsValid)
            {
                if (memberShip.ValidateUser(model.Person.Email, model.Person.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.Person.Email, false);
                    if (Url.IsLocalUrl(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Неправильный пароль или логин");
                }
            }
            return(View(model));
        }
コード例 #2
0
        public ActionResult Register(AuthenticationViewModel model)
        {
            if (ModelState.IsValid)
            {
                PersonMembershipProvider memberShip     = new PersonMembershipProvider();
                MembershipUser           membershipUser = memberShip.CreateUser(model.Person);

                if (membershipUser != null)
                {
                    FormsAuthentication.SetAuthCookie(model.Person.Email, false);
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "Ошибка при регистрации");
                }
            }
            return(View(model));
        }