public async Task<ActionResult> Login(AccountLoginModel viewModel) { // Ensure we have a valid viewModel to work with if (!ModelState.IsValid) return View(viewModel); // Verify if a user exists with the provided identity information var user = await _manager.FindByEmailAsync(viewModel.Email); // If a user was found if (user != null) { // Then create an identity for it and sign it in await SignInAsync(user, viewModel.RememberMe); // If the user came from a specific page, redirect back to it return RedirectToLocal(viewModel.ReturnUrl); } // No existing user was found that matched the given criteria ModelState.AddModelError("", "Invalid username or password."); // If we got this far, something failed, redisplay form return View(viewModel); }
public ActionResult Login(string returnUrl) { // We do not want to use any existing identity information EnsureLoggedOut(); // Store the originating URL so we can attach it to a form field var viewModel = new AccountLoginModel { ReturnUrl = returnUrl }; return View(viewModel); }
//[ValidateAntiForgeryToken] public ActionResult Login(AccountLoginModel viewModel, string returnUrl = "/admin", FormCollection f = null) { // fcamarena / 12345 // Ensure we have a valid viewModel to work with if (!ModelState.IsValid) { var message = ""; if (ModelState[""] == null) { message = " An error occurred."; } else { foreach (var error in ModelState[""].Errors) { message = error.ErrorMessage + "\r\n"; } } return Json(new { Success = false, Message = message, }, JsonRequestBehavior.AllowGet); } try { var auth = AUTH(viewModel.jwt_token); if (auth != null) { this.usuarioAPI = auth; if (viewModel.RememberMe) { SetRememberMeCookie(viewModel.UserName, viewModel.Password); } else { RemoveRememberMeCookie(); } SetTokenCookie(viewModel.jwt_token); // 15min SetIsAuthenticated(true); // If the user came from a specific page, redirect back to it //return RedirectToLocal(returnUrl); return Json(new { Success = true, ReturnUrl = returnUrl, }, JsonRequestBehavior.AllowGet); } } catch (Exception ex) { return Json(new { Success = false, Message = ex.ToString(), }, JsonRequestBehavior.AllowGet); } return Json(new { Success = false, Message = "An error occurred.", }, JsonRequestBehavior.AllowGet); }