firts commit
This commit is contained in:
145
KART_API/Controllers/SecurityController.cs
Normal file
145
KART_API/Controllers/SecurityController.cs
Normal file
@@ -0,0 +1,145 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using KART_API.Services;
|
||||
using KART_API.Utils;
|
||||
using KART_API.Dto;
|
||||
using System.Data;
|
||||
using System;
|
||||
using System.Net;
|
||||
|
||||
namespace KART_API.Controllers
|
||||
{
|
||||
[Route("api/v2/encrypt")]
|
||||
[ApiController]
|
||||
public class SecurityController : ControllerBase
|
||||
{
|
||||
|
||||
[Route("pkey")]//확인
|
||||
[HttpGet]
|
||||
public IActionResult EncryptString([FromHeader] string token, [FromHeader]string pkey)
|
||||
{
|
||||
HttpContextAccessor hcAccessor = new HttpContextAccessor();
|
||||
hcAccessor.HttpContext.Response.ContentType = "text/plain";
|
||||
|
||||
UserInfo userInfo = Security.ValidateToken(token);
|
||||
if (userInfo != null)
|
||||
{
|
||||
ProjectService project = new ProjectService();
|
||||
if (project.getProjectInfo(pkey).Rows.Count > 0)
|
||||
{
|
||||
Security security = new Security();
|
||||
string 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";
|
||||
|
||||
UserService user = new UserService();
|
||||
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, 4:BC 팀, 5:타부서, 6:외부인 인데 파생변수까지 접근, 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";
|
||||
}
|
||||
|
||||
LogService.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 == "NS" || externalParam.External == "KON" || externalParam.External == "KIWI" || externalParam.External == "CLIENT")
|
||||
{
|
||||
string returnString = "";
|
||||
LogService.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user