firts commit

This commit is contained in:
2025-10-24 10:25:54 +09:00
commit edf42de8f9
45 changed files with 133446 additions and 0 deletions

View File

@@ -0,0 +1,150 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using REPORT_API_ver6.Services;
using REPORT_API_ver6.Models;
using System.Data;
using System;
using System.Net;
namespace REPORT_API_ver6.Controllers
{
[Route("api/v1/encrypt")]
[ApiController]
public class SecurityAPI : ControllerBase
{
[Route("pkey")]
[HttpGet]
public IActionResult EncryptString([FromHeader] string token, [FromHeader]string pkey, [FromHeader]string iskiwi)
{
HttpContextAccessor hcAccessor = new HttpContextAccessor();
hcAccessor.HttpContext.Response.ContentType = "text/plain";
UserInfo userInfo = Security.ValidateToken(token);
if (userInfo != null)
{
Project project = new Project();
if (project.getProjectInfo(pkey, Convert.ToInt32(iskiwi)).Rows.Count > 0)
{
string returnString = string.Empty;
Security security = new Security();
if (iskiwi == "1")
{
pkey = "|K|W|" + pkey;
}
returnString = WebUtility.UrlEncode(security.encryptString(pkey));
Response.StatusCode = (int)HttpStatusCode.OK;
return Content(returnString);
}
}
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
return Content(null);
}
[Route("login")]
[HttpPost]
public IActionResult Login([FromBody] LoginParam login)
{
HttpContextAccessor hcAccessor = new HttpContextAccessor();
hcAccessor.HttpContext.Response.ContentType = "application/json";
User user = new User();
DataTable userTable = user.userLogin(login.ID, login.Password);
if (userTable.Rows.Count > 0)
{
string returnString = "";
string userID = userTable.Rows[0]["mail"].ToString();
string userPNO = userTable.Rows[0]["p_no"].ToString();
string userName = userTable.Rows[0]["member_name"].ToString();
string userTeam = userTable.Rows[0]["team"].ToString();
string isKri = userTable.Rows[0]["is_kri"].ToString();
// isAdmin - 0 : Admin, 1:DCO, 5:타부서, 7:클라이언트, 9:외부 링크
string isAdmin = "7";
if (userID == "jspark@kric.com")
{
isAdmin = "0";
}
else if (userTeam == "S301" || userTeam == "S401" || userTeam == "S501" || userPNO == "20191201")//온라인 사업, 데이터 사업, 개발팀 + 서지원 상무
{
isAdmin = "1";
}
else if (isKri == "1")
{
isAdmin = "4";
}
else if (isKri == "2")
{
isAdmin = "5";
}
else if (isKri == "3")
{
isAdmin = "6";
}
Log.insertLoginLog(userID);
Security security = new Security();
string token = security.GenerateToken(userID, userName, userTeam, isAdmin);
Authentication authentication = new Authentication(token, userName, isAdmin);
returnString = Common.GetJsonFromObject(authentication);
Response.StatusCode = (int)HttpStatusCode.OK;
return Content(returnString);
}
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
return Content(null);
}
[Route("authentication")]
[HttpGet]
public IActionResult Authentication([FromHeader] string token)
{
HttpContextAccessor hcAccessor = new HttpContextAccessor();
hcAccessor.HttpContext.Response.ContentType = "text/plain";
UserInfo userInfo = Security.ValidateToken(token);
if (userInfo != null)
{
Response.StatusCode = (int)HttpStatusCode.OK;
return Content(null);
}
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
return Content(null);
}
[Route("external")]
[HttpPost]
public IActionResult External([FromBody] ExternalParam externalParam)
{
HttpContextAccessor hcAccessor = new HttpContextAccessor();
hcAccessor.HttpContext.Response.ContentType = "text/plain";
if (externalParam.External == "KON" || externalParam.External == "KIWI" || externalParam.External == "CLIENT")
{
string returnString = "";
Log.insertLoginLog(externalParam.External);
Security security = new Security();
string tempID = externalParam.External + "_" + Common.GetRandomString();
string token = security.GenerateToken(tempID, externalParam.External, externalParam.External, "9");
Authentication authentication = new Authentication(token, externalParam.External, "9");
returnString = Common.GetJsonFromObject(authentication);
Response.StatusCode = (int)HttpStatusCode.OK;
return Content(returnString);
}
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
return Content(null);
}
}
}