Exemplo n.º 1
0
        public IActionResult Login(Login innLogin)
        {
            if (ModelState.IsValid)
            {
                var innloggingOK = _admin.ValiderLogin(innLogin);

                if (innloggingOK)
                {
                    var identity = new ClaimsIdentity(new[]
                    {
                        new Claim(ClaimTypes.Name, innLogin.Brukernavn)
                    }, CookieAuthenticationDefaults.AuthenticationScheme);

                    var principal = new ClaimsPrincipal(identity);

                    HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal);
                    return(RedirectToAction("AdminPanel"));
                }
            }

            ViewBag.Error = "Feil brukernavn eller password";
            return(View("Login"));
        }