ปรับปรุงกระบวนการตรวจจับการ login

This commit is contained in:
Nakorn Rientrakrunchai
2020-03-01 10:42:42 +07:00
parent 9fe55ebeea
commit c65c179e85
29 changed files with 342 additions and 195 deletions

View File

@@ -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"]))