Example #1
0
        public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            var user = UserManager.FindByEmail(model.Email);

            if (user != null)
            {
                if (UserManager.IsEmailConfirmedAsync(user.Id).Result)
                {
                    if (user.BusinessInfo.AddressVerificationStatus == AddressVerificationStatus.Verified)
                    {
                        var result = SignInManager.PasswordSignIn(model.Email, model.Password, model.RememberMe,
                                                                  shouldLockout: true);

                        switch (result)
                        {
                        case SignInStatus.Success:
                            return(RedirectToAction("Index", "Home"));

                        case SignInStatus.Failure:
                            ModelState.AddModelError("", "Incorrect email or password.");
                            return(View());

                        case SignInStatus.LockedOut:
                            ModelState.AddModelError("",
                                                     "Too many login attempts, you have been temporarily locked out.");
                            return(View());

                        case SignInStatus.RequiresVerification:
                            ModelState.AddModelError("", "Login with this account requires firther verification.");
                            return(View());

                        default:
                            return(View());
                        }
                    }
                    return(View("RequireAddressVerification"));
                }
                return(View("RequireEmailVerification"));
            }
            ModelState.AddModelError("", "Incorrect email or password.");
            return(View());
        }
Example #2
0
        public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            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);
            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.");
                    return View(model);
            }
        }