Ejemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync(string account, string password)
        {
            try
            {
                if (string.IsNullOrEmpty(account) && string.IsNullOrEmpty(password))
                {
                    return(LocalRedirect("/"));
                }

                await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);

                var user = await maskDataBase.Login(new AccountModel()
                {
                    Account = account, Password = password
                });

                if (user == null)
                {
                    return(LocalRedirect("/"));
                }
                var claims = new List <Claim>
                {
                    new Claim(ClaimTypes.Name, account),
                    new Claim(ClaimTypes.Role, user.Level)
                };
                var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
                var authProperties = new AuthenticationProperties
                {
                    IsPersistent = true,
                    RedirectUri  = this.Request.Host.Value
                };
                await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity), authProperties);
            }
            finally
            {
            }
            return(LocalRedirect("/"));
        }
Ejemplo n.º 2
0
 public async Task <AccountModel> Login(AccountModel account)
 {
     return(await maskDataBase.Login(account));
 }