public async Task<JsonResult> JsonLogin(LoginViewModel model, string returnUrl) { if (this.ModelState.IsValid) { var user = await this.UserManager.FindAsync(model.Email, model.Password); if (user != null) { await this.SignInAsync(user, model.RememberMe); return this.Json(new { success = true, redirect = returnUrl }); } else { this.ModelState.AddModelError("", "The user name or password provided is incorrect."); } } // If we got this far, something failed return this.Json(new { errors = this.GetErrorsFromModelState() }); }
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl) { if (this.ModelState.IsValid) { var user = await this.UserManager.FindAsync(model.Email, model.Password); if (user != null) { await this.SignInAsync(user, model.RememberMe); return this.RedirectToLocal(returnUrl); } else { this.ModelState.AddModelError("", "Invalid username or password."); } } // If we got this far, something failed, redisplay form return this.View(model); }