public async Task <IActionResult> Login(DTOLogin loginModel, string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (ModelState.IsValid) { var personel = await _personelService.Login(loginModel); if (personel != null) { var claims = new List <Claim> { new Claim(ClaimTypes.Name, personel.PersonelId.ToString()) }; var userIdentity = new ClaimsIdentity(claims, "login"); ClaimsPrincipal principal = new ClaimsPrincipal(userIdentity); await HttpContext.SignInAsync(principal); return(LocalRedirect(returnUrl)); } else { ModelState.AddModelError("CustomError", "Personel adi veya şifresi yanlış!"); } } return(View()); }
private void btnLogin_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtIdentity.Text)) { MessageBox.Show("You Have To Enter Identity Numb"); return; } else if (string.IsNullOrEmpty(txtPassword.Text)) { MessageBox.Show("You Have To Enter Password"); return; } var personel = _personelService.Login(txtIdentity.Text, txtPassword.Text); if (personel != null) { MessageBox.Show("Login Succesfull"); MasterForm.WindowState = FormWindowState.Normal; this.Hide(); } else { MessageBox.Show("Invalid Identity Number Or Password"); } }