Пример #1
0
        public ActionResult LogIn(AuthLogInModel model)
        {
            if (!ModelState.IsValid)
            {
                return View();
            }

            User user = userManager.Find(model.UserName, model.Password);
            if (user != null)
            {
                IAuthenticationManager authenticationManager = HttpContext.GetOwinContext().Authentication;
                authenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
                ClaimsIdentity identity = userManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
                AuthenticationProperties props = new AuthenticationProperties();
                props.IsPersistent = model.RememberMe;
                authenticationManager.SignIn(props, identity);
                if (Url.IsLocalUrl(model.ReturnUrl))
                {
                    return Redirect(model.ReturnUrl);
                }
                else
                {
                    return RedirectToAction("Index", "Question");
                }
            }
            else
            {
                ModelState.AddModelError("", "Invalid username or password.");
            }

            return View();
        }
Пример #2
0
        public ActionResult LogIn(string returnUrl)
        {
            var model = new AuthLogInModel
            {
                ReturnUrl = returnUrl
            };

            return View(model);
        }