コード例 #1
0
        public async Task <IActionResult> Login(LoginModel Ulogin)
        {
            if (_userlogin.CheckPass(Ulogin) == true && _userlogin.isAdmin(Ulogin.Username) && ModelState.IsValid)
            {
                var ownRole = new List <Claim>();
                ownRole.Add(new Claim(ClaimTypes.Role, "admin"));//databaseden gelen nesnenın
                ownRole.Add(new Claim(ClaimTypes.Name, Ulogin.Username));
                ownRole.Add(new Claim(ClaimTypes.Hash, Sha256.ComputeSha256Hash(Ulogin.Password)));
                var ownIdentity  = new ClaimsIdentity(ownRole, CookieAuthenticationDefaults.AuthenticationScheme);
                var ownPrincipal = new ClaimsPrincipal(ownIdentity);
                var ownSchema    = CookieAuthenticationDefaults.AuthenticationScheme;
                await HttpContext.SignInAsync(ownSchema, ownPrincipal);

                HttpContext.Session.SetString("currentUser", Ulogin.Username);
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                return(View(Ulogin));
            }
        }