public async Task <IActionResult> Login([Bind] LoginViewModel model) { if (ModelState.IsValid) { string LoginStatus = _authService.AdminLogin(model); if (LoginStatus == "Success") { var claims = new List <Claim> { new Claim(ClaimTypes.Name, model.Username), new Claim(ClaimTypes.Role, RoleEnum.Admin.ToString()) }; ClaimsIdentity userIdentity = new ClaimsIdentity(claims, "login"); ClaimsPrincipal principal = new ClaimsPrincipal(userIdentity); await HttpContext.SignInAsync(principal); return(RedirectToAction("Index", "Home")); } else { TempData["LoginStatus"] = "Login Failed.Please enter correct credentials"; return(View()); } } else { return(View()); } }
public ActionResult Index(AdminLoginDto adminDto) { if (authService.AdminLogin(adminDto)) { //yönlendrime işlemleri FormsAuthentication.SetAuthCookie(adminDto.AdminUsername, false); Session["AdminUsername"] = adminDto.AdminUsername; return(RedirectToAction("Index", "Heading")); } else { //Hata Mesajı döndür ViewData["ErrorMessage"] = "Kullanıcı Adı veya Parola Yanlış!"; return(View()); } }