Ejemplo n.º 1
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
            QLLINHKIENEntities db   = new QLLINHKIENEntities();
            AspNetUser         user = db.AspNetUsers.FirstOrDefault(m => m.Email == model.Email);

            if (user == null)
            {
                ModelState.AddModelError("CustomError", "Tài khoản không tồn tại !!!");
                return(View(model));
            }

            else
            {
                if (user.EmailConfirmed == false)
                {
                    ModelState.AddModelError("CustomError", "Tài khoản chưa xác thực !!!");
                    return(View(model));
                }
            }

            var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false);

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

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Sai tài khoản hoặc mật khẩu !!!");
                return(View(model));
            }
        }