public async Task <ActionResult> LogIn(PostLoginDTO model, string returnUrl) { if (ModelState.IsValid) { User user = await _accountsService.Login(model); 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(returnUrl)) { return(Redirect(returnUrl)); } else { return(RedirectToAction("Index", "Advert")); } } else { ModelState.AddModelError("", "Invalid username or password."); } } return(View(model)); }
public async Task <User> Login(PostLoginDTO model) { if (model == null) { throw new ArgumentNullException(); } var user = await userManager.FindAsync(model.UserName, model.Password); return(user); }