public async Task<ActionResult> Login(LoginViewModel model, string returnUrl) { if (!this.ModelState.IsValid) { return this.View(model); } // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, change to shouldLockout: true var result = await this.SignInManager.PasswordSignInAsync(model.Username, model.Password, model.RememberMe, false); switch (result) { case SignInStatus.Success: FormsAuthentication.SetAuthCookie(model.Username, true); return this.RedirectToLocal(returnUrl); case SignInStatus.LockedOut: return this.View("Lockout"); case SignInStatus.RequiresVerification: return this.RedirectToAction("SendCode", new { ReturnUrl = returnUrl, model.RememberMe }); case SignInStatus.Failure: default: this.ModelState.AddModelError("", "Invalid login attempt."); return this.View(model); } }
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl) { if (!this.ModelState.IsValid) { return this.View(model); } var result = await this.SignInManager .PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false); switch (result) { case SignInStatus.Success: return this.RedirectToLocal(returnUrl); case SignInStatus.LockedOut: return this.View("Lockout"); case SignInStatus.RequiresVerification: return this.RedirectToAction( "SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }); case SignInStatus.Failure: default: this.ModelState.AddModelError("", "Invalid login attempt."); return View(model); } }
public ActionResult Login(ViewModels.LoginViewModel loginViewModel, string ReturnUrl = "/") { if (ModelState.IsValid) { var user = DatabaseContext.Users .Where(current => current.EmailAddress == loginViewModel.EmailAddress) .Where(current => current.Password == loginViewModel.Password) .FirstOrDefault(); if (user != null) { if (user.IsActive) { FormsAuthentication.SetAuthCookie(user.Username, loginViewModel.RememberMe); return(Redirect(url: ReturnUrl)); } else { ModelState.AddModelError(loginViewModel.EmailAddress, "حساب کاربری شما فعال نشده است"); } } else { ModelState.AddModelError(loginViewModel.EmailAddress, "اطلاعات وارد شده صحیح نمی باشد لطفا مجددا تلاش نمایید"); } } return(View(loginViewModel)); }
/// <summary> /// Initializes a new instance of the <see cref="LoginView" /> class. /// </summary> /// <param name="vm"> /// The vm. /// </param> public LoginView(LoginViewModel vm) { try { InitializeComponent(); DataContext = vm; } catch (Exception ex) { ex.Source = "Login View, init"; Exceptions.HandleException(ex); } }
public async Task<IActionResult> Login(LoginViewModel model) { model.ExternalProviders = signInManager.GetExternalAuthenticationSchemes().ToArray(); if (!ModelState.IsValid) { model.Errors.AddModelStateErrors(ModelState); return View(model); } var result = await signInManager.PasswordSignInAsync(model.Email, model.Password, false, true); if (result.Succeeded) { return RedirectToAction("Index", "Home"); } model.Errors.Add("Sign-in failed. Please try again. If you cannot sign-in you might not be registered"); return View(model); }
public async Task<IActionResult> Login(LoginViewModel vm, string returnUrl) { if (this.ModelState.IsValid) { var signInResult = await this.signInManager.PasswordSignInAsync(vm.Username, vm.Password, true, false); if (signInResult.Succeeded) { if (string.IsNullOrWhiteSpace(returnUrl)) { return RedirectToAction("Trips", "App"); } return Redirect(returnUrl); } else { this.ModelState.AddModelError(string.Empty, "Username or password incorrect"); } } return View(); }
public ActionResult Login(LoginViewModel model) { // Lets first check if the Model is valid or not if (ModelState.IsValid) { string username = model.UserName; string password = model.Password; User user = this.db.Query<User>().Where(i => i.EmailAddress == username).FirstOrDefault(); if (user != null) { bool userValid = PasswordHash.ValidatePassword(password, user.Password); // User found in the database if (userValid) { Log.Write(this.db, ControllerContext.HttpContext, new Log() { Message = LogMessages.logon, Detail = "User successfully logged on.", User = username }); string returnUrl = model.ReturnUrl; this.auth.DoAuth(username, false); ActionResult response = Redirect(returnUrl); return response; } } ModelState.AddModelError(string.Empty, "The User Name or password provided is incorrect."); Log.Write(this.db, ControllerContext.HttpContext, new Log() { Message = LogMessages.incorrectlogon, Detail = "There was an incorrect login attempt.", User = username }); } // If we got this far, something failed, redisplay form return this.View(model); }
public ActionResult Login(string returnUrl) { LoginViewModel model = new LoginViewModel { ReturnUrl = returnUrl }; return this.View(model); }