ปรับปรุงกระบวนการตรวจจับการ login
This commit is contained in:
@@ -7,6 +7,8 @@ using System.Data;
|
||||
using System.Reflection;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Net;
|
||||
using TodoAPI2.Models;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
/// <summary>
|
||||
/// Summary description for MyHelper
|
||||
@@ -258,6 +260,28 @@ public class MyHelper
|
||||
return httpclient;
|
||||
}
|
||||
|
||||
public static void get_login(Microsoft.AspNetCore.Http.HttpContext HttpContext,
|
||||
Iexternal_employeeService _repository,
|
||||
Microsoft.AspNetCore.Http.HttpResponse Response
|
||||
)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(HttpContext.Request.Cookies["user_id"]))
|
||||
{
|
||||
string loginid = HttpContext.Request.Cookies["user_id"];
|
||||
var emp = _repository.GetEmployeeForLogin(Convert.ToInt32(loginid));
|
||||
if (emp != null)
|
||||
{
|
||||
Response.Cookies.Delete("emp_name");
|
||||
Response.Cookies.Delete("emp_id");
|
||||
|
||||
CookieOptions option = new CookieOptions();
|
||||
option.Expires = DateTime.Now.AddHours(3);
|
||||
Response.Cookies.Append("emp_name", emp.fullname, option);
|
||||
Response.Cookies.Append("emp_id", emp.id.ToString(), option);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool checkAuth(IConfiguration Configuration, Microsoft.AspNetCore.Http.HttpContext context)
|
||||
{
|
||||
//if (!string.IsNullOrEmpty(context.Request.Cookies["user_id"]))
|
||||
|
||||
Reference in New Issue
Block a user