public IActionResult LogInAction([FromBody] loginstruct login) { if (ModelState.IsValid) { var Thisuser = db.tbl_user.SingleOrDefault(a => a.username == login.username && a.password == login.password); if (Thisuser == null) { return(Json(new { message = "کاربری با چنین مشخصات وجود ندارد", status = "NoUser" })); } if (Thisuser.status) { var claims = new List <Claim>() { new Claim(ClaimTypes.NameIdentifier, Thisuser.id.ToString()), new Claim(ClaimTypes.Name, login.username), //new Claim(nameof(Thisuser.Lname),Thisuser.Lname), }; var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); var principal = new ClaimsPrincipal(identity); var properties = new AuthenticationProperties { IsPersistent = login.RememberMe }; HttpContext.SignInAsync(principal, properties); // //fill accessibilityaction tables for this user //ToDo in other part in this site; // return(Json(new { message = "کاربر با موفقیت وارد سایت شد", status = "success", username = Thisuser.username })); } else { return(Json(new { message = "کاربر غیر فعال می باشد", status = "notactive" })); } } else { return(Json(new { message = ModelState.Values.SelectMany(v => v.Errors).Select(x => x.ErrorMessage).ToList(), status = "validationerror" })); } }
//[Route("Login")] public IActionResult LogIn() { loginstruct model = new loginstruct(); return(PartialView("~/Views/Shared/NewLayoutPartial/_PartialLogIn.cshtml", model)); }