Exemplo n.º 1
0
 public ActionResult Login(string returnURL)
 {
     if (string.IsNullOrWhiteSpace(returnURL))
         returnURL = Request.UrlReferrer.LocalPath;
     var model = new LoginModel() { ReturnURL = returnURL };
     return View(model);
 }
Exemplo n.º 2
0
        public async Task<ActionResult> LogIn(LoginModel model)
        {
            if (!ModelState.IsValid)
            {
                return View();
            }

            var user = await userManager.FindAsync(model.Username, model.Password);

            if (user != null)
            {
                var identity = await userManager.CreateIdentityAsync(
                    user, DefaultAuthenticationTypes.ApplicationCookie);

                GetAuthenticationManager().SignIn(identity);

                return Redirect(GetRedirectUrl(model.ReturnURL));
            }

            ModelState.AddModelError("", "Invalid email or password");
            return View(model);
        }