public async Task <ActionResult> ExternalLoginCallback(LoginViewModel model, string returnUrl) { bool aService = new DAL.ApplicantDatabaseDataService().ReadIsActive(model.Email); bool bService = new DAL.BusinessDatabaseDataService().ReadIsActive(model.Email); var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(); if (loginInfo == null) { return(RedirectToAction("RegisterIndex", "Account")); } //Sign in the user with this external login provider if the user already has a login var result = await SignInManager.ExternalSignInAsync(loginInfo, isPersistent : false); if (result == SignInStatus.Success || aService || bService) { return(RedirectToLocal(returnUrl)); } switch (result) { case SignInStatus.LockedOut: return(View("Lockout")); case SignInStatus.RequiresVerification: return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = false })); case SignInStatus.Failure: default: //If the user does not have an account, then prompt the user to create an account ViewBag.ReturnUrl = returnUrl; ViewBag.LoginProvider = loginInfo.Login.LoginProvider; return(RedirectToAction("RegisterIndex", "Account")); //return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { Email = loginInfo.Email }); } }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { bool aService = new DAL.ApplicantDatabaseDataService().ReadIsActive(model.Email); bool bService = new DAL.BusinessDatabaseDataService().ReadIsActive(model.Email); bool adService = new DAL.AdminDAL.AdminDatabaseDataService().ReadIsActive(model.Email); string activeStatus = ""; if (!ModelState.IsValid) { return(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 SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false); if (result == SignInStatus.Success && !aService && !bService && !adService) { result = SignInStatus.Failure; activeStatus = "Your account is currently inactive."; } switch (result) { case SignInStatus.Success: return(RedirectToLocal(returnUrl)); case SignInStatus.LockedOut: return(View("Lockout")); case SignInStatus.RequiresVerification: return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe })); case SignInStatus.Failure: default: ModelState.AddModelError("", "Invalid login attempt." + activeStatus); return(View(model)); } }