示例#1
0
        public async Task<IActionResult> Login(string email, string password)
        {
            if (ModelState.IsValid)
            {
                if (_iUserBLL.CredentialsExist(email, password))
                {
                    if(!_iUserBLL.CheckStatus(email))
                    {
                        var claims = new List<Claim>
                    {
                        new Claim(ClaimTypes.Name, _iUserBLL.GetUserName(email)),
                        new Claim(ClaimTypes.Role, _iUserBLL.GetUserRole(email)),
                        new Claim(ClaimTypes.SerialNumber, _iUserBLL.GetUserId(email).ToString()),
                        new Claim(ClaimTypes.Email, email)
                    };

                        ClaimsIdentity identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
                        ClaimsPrincipal principal = new ClaimsPrincipal(identity);

                        var authenticationProperties = new AuthenticationProperties
                        {
                            IsPersistent = false,
                        };

                        await HttpContext.SignInAsync(principal, authenticationProperties);

                        return RedirectToAction("Index", "Home");
                    }
                    else
                    {
                        ModelState.AddModelError("Password", "Account is banned.");
                    }
                }
                else
                {
                    ModelState.AddModelError("Password", "Email and/or Password wrong");

                    return View();
                }
            }
            return View();
        }