public async Task <ActionResult> Login(LoginViewModel model, string returnUrl, string invitationCode) { if (!ModelState.IsValid || (ViewBag.Settings.LocalLoginByEmail && string.IsNullOrWhiteSpace(model.Email)) || (!ViewBag.Settings.LocalLoginByEmail && string.IsNullOrWhiteSpace(model.Username))) { //AddErrors(ViewBag.IdentityErrors.InvalidLogin()); AddErrors(new IdentityError() { Description = " Invalid sign-in attempt. Please enter the correct user access credentials." }); return(View(GetLoginViewModel(model, null, returnUrl, invitationCode))); } var rememberMe = ViewBag.Settings.RememberMeEnabled && model.RememberMe; BranchSettingsViewModel userBranchConfiguration = UserBranchConfiguration(model.Username); if (userBranchConfiguration.BranchName != string.Empty && !userBranchConfiguration.IsBranchConfigured) { AddErrors(new IdentityError() { Description = " Your branch has not been configured. Please contact your system administrator to fix this." }); return(View(GetLoginViewModel(model, null, returnUrl, invitationCode))); } setUserBranchCookie(userBranchConfiguration); // This doen't count login failures towards lockout only two factor authentication // To enable password failures to trigger lockout, change to shouldLockout: true SignInStatus result = ViewBag.Settings.LocalLoginByEmail ? await SignInManager.PasswordSignInByEmailAsync(model.Email, model.Password, rememberMe, ViewBag.Settings.TriggerLockoutOnFailedPassword) : await SignInManager.PasswordSignInAsync(model.Username, model.Password, rememberMe, ViewBag.Settings.TriggerLockoutOnFailedPassword); switch (result) { case SignInStatus.Success: return(await RedirectOnPostAuthenticate(returnUrl, invitationCode)); case SignInStatus.LockedOut: AddErrors(ViewBag.IdentityErrors.UserLocked()); return(View(GetLoginViewModel(model, null, returnUrl, invitationCode))); case SignInStatus.RequiresVerification: return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, InvitationCode = invitationCode, RememberMe = rememberMe })); case SignInStatus.Failure: default: AddErrors(new IdentityError() { Description = " Invalid sign-in attempt. Please enter the correct user access credentials." }); //AddErrors(ViewBag.IdentityErrors.InvalidLogin()); return(View(GetLoginViewModel(model, null, returnUrl, invitationCode))); } }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl, string invitationCode) { if (!ModelState.IsValid || (ViewBag.Settings.LocalLoginByEmail && string.IsNullOrWhiteSpace(model.Email)) || (!ViewBag.Settings.LocalLoginByEmail && string.IsNullOrWhiteSpace(model.Username))) { AddErrors(ViewBag.IdentityErrors.InvalidLogin()); return(View(GetLoginViewModel(model, null, returnUrl, invitationCode))); } var rememberMe = ViewBag.Settings.RememberMeEnabled && model.RememberMe; // This doen't count login failures towards lockout only two factor authentication // To enable password failures to trigger lockout, change to shouldLockout: true SignInStatus result = ViewBag.Settings.LocalLoginByEmail ? await SignInManager.PasswordSignInByEmailAsync(model.Email, model.Password, rememberMe, ViewBag.Settings.TriggerLockoutOnFailedPassword) : await SignInManager.PasswordSignInAsync(model.Username, model.Password, rememberMe, ViewBag.Settings.TriggerLockoutOnFailedPassword); switch (result) { case SignInStatus.Success: return(await RedirectOnPostAuthenticate(returnUrl, invitationCode)); case SignInStatus.LockedOut: AddErrors(ViewBag.IdentityErrors.UserLocked()); return(View(GetLoginViewModel(model, null, returnUrl, invitationCode))); case SignInStatus.RequiresVerification: return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, InvitationCode = invitationCode, RememberMe = rememberMe })); case SignInStatus.Failure: default: AddErrors(ViewBag.IdentityErrors.InvalidLogin()); return(View(GetLoginViewModel(model, null, returnUrl, invitationCode))); } }