[♻️] User 파트와 Push 파트 리팩토링 진행
This commit is contained in:
parent
e20ac8bdbc
commit
e8a2f3d7ee
|
@ -76,6 +76,9 @@ public class JwtTokenService
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 여기는 엑세스 토큰의 확인을 위한 jwt 서비스 내의 인증 메서드
|
||||||
|
/// </summary>
|
||||||
public ClaimsPrincipal ValidateToken(string token)
|
public ClaimsPrincipal ValidateToken(string token)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(token)) return null;
|
if (string.IsNullOrWhiteSpace(token)) return null;
|
||||||
|
|
|
@ -25,6 +25,7 @@ public class PushController : ControllerBase
|
||||||
public IActionResult GetPushData()
|
public IActionResult GetPushData()
|
||||||
{
|
{
|
||||||
return Ok("SEND");
|
return Ok("SEND");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,51 +40,67 @@ public class PushController : ControllerBase
|
||||||
/// <response code="500">Internal server error occurred.</response>
|
/// <response code="500">Internal server error occurred.</response>
|
||||||
/// <response code="999">Service unavailable.</response>
|
/// <response code="999">Service unavailable.</response>
|
||||||
[HttpPost("send")]
|
[HttpPost("send")]
|
||||||
[CustomOperation("푸시전송", "저장된 양식으로, 사용자에게 푸시를 전송한다.", "푸시")]
|
[CustomOperation("푸시전송", "저장된 양식으로, 사용자에게 푸시를 전송한다.(로컬 테스트 불가)", "푸시")]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(APIResponseStatus<object>))]
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(APIResponseStatus<object>))]
|
||||||
public async Task<IActionResult> SendPush(string deviceToken, [FromBody] Payload? payload)
|
public async Task<IActionResult> SendPush(string deviceToken, [FromBody] Payload? payload)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(deviceToken))
|
if (string.IsNullOrWhiteSpace(deviceToken) || payload == null)
|
||||||
|
return BadRequest(APIResponse.InvalidInputError());
|
||||||
|
|
||||||
|
// string uri = "";
|
||||||
|
// string p12Path = "";
|
||||||
|
//
|
||||||
|
// string p12PWPath = "/src/private/appleKeys.json";
|
||||||
|
//
|
||||||
|
// // 앱 번들 ID 입력 부분
|
||||||
|
// string apnsTopic = "me.myds.ipstein.acamate.AcaMate";
|
||||||
|
|
||||||
|
Func<bool,string,string, ApnsPushService> pushService = (isDevelopment,pw,topic) =>
|
||||||
{
|
{
|
||||||
var inputError = APIResponse.InvalidInputError;
|
if (isDevelopment)
|
||||||
// inputError.status.message = "Deviece Toekn 오류";
|
|
||||||
return StatusCode(500,inputError);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (payload == null)
|
|
||||||
{
|
{
|
||||||
var inputError = APIResponse.InvalidInputError;
|
return new ApnsPushService(
|
||||||
// inputError.status.message = "payload 입력 오류";
|
"https://api.sandbox.push.apple.com/",
|
||||||
return StatusCode(500,inputError);
|
"/src/private/AM_Push_Sandbox.p12",
|
||||||
}
|
pw, topic
|
||||||
|
);
|
||||||
string uri = "";
|
|
||||||
string p12Path = "";
|
|
||||||
string p12PWPath = "/src/private/appleKeys.json";
|
|
||||||
// string p12PWPath = "private/appleKeys.json";
|
|
||||||
string apnsTopic = "me.myds.ipstein.acamate.AcaMate";
|
|
||||||
|
|
||||||
|
|
||||||
if (_env.IsDevelopment())
|
|
||||||
{
|
|
||||||
uri = "https://api.sandbox.push.apple.com/";
|
|
||||||
p12Path = "/src/private/AM_Push_Sandbox.p12";
|
|
||||||
// p12Path = "private/AM_Push_Sandbox.p12";
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
uri = "https://api.push.apple.com/";
|
return new ApnsPushService(
|
||||||
p12Path = "/src/private/AM_Push.p12";
|
"https://api.push.apple.com/",
|
||||||
// p12Path = "private/AM_Push.p12";
|
"/src/private/AM_Push.p12",
|
||||||
|
pw, topic
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
//
|
||||||
|
// if (_env.IsDevelopment())
|
||||||
|
// {
|
||||||
|
// uri = "https://api.sandbox.push.apple.com/";
|
||||||
|
// p12Path = "/src/private/AM_Push_Sandbox.p12";
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// uri = "https://api.push.apple.com/";
|
||||||
|
// p12Path = "/src/private/AM_Push.p12";
|
||||||
|
// }
|
||||||
|
//
|
||||||
// ApnsPushService 인스턴스 생성
|
// ApnsPushService 인스턴스 생성
|
||||||
var pushService = new ApnsPushService(uri, p12Path, p12PWPath, apnsTopic);
|
// var pushService = new ApnsPushService(uri, p12Path, p12PWPath, apnsTopic);
|
||||||
|
//
|
||||||
|
|
||||||
// 푸시 알림 전송
|
// 푸시 알림 전송
|
||||||
var result = await pushService.SendPushNotificationAsync(deviceToken, payload);
|
// var result = await pushService.SendPushNotificationAsync(deviceToken, payload);
|
||||||
|
|
||||||
|
var result = await pushService(
|
||||||
|
_env.IsDevelopment(),
|
||||||
|
"/src/private/appleKeys.json",
|
||||||
|
"me.myds.ipstein.acamate.AcaMate"
|
||||||
|
).SendPushNotificationAsync(deviceToken, payload);
|
||||||
|
|
||||||
if (result.Success)
|
if (result.Success)
|
||||||
{
|
{
|
||||||
return Ok(APIResponse.Success());
|
return Ok(APIResponse.Success());
|
||||||
|
|
|
@ -38,14 +38,18 @@ public class UserController : ControllerBase
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[CustomOperation("회원 정보 조회", "회원 정보 조회", "사용자")]
|
[CustomOperation("회원 정보 조회", "회원 정보 조회", "사용자")]
|
||||||
public IActionResult GetUserData(string uid)
|
public async Task<IActionResult> GetUserData(string token, string refresh)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(uid)) return BadRequest(APIResponse.InvalidInputError());
|
if(string.IsNullOrEmpty(token) || string.IsNullOrEmpty(refresh))
|
||||||
|
return BadRequest(APIResponse.InvalidInputError());
|
||||||
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var user = _dbContext.User
|
var validateToken = await _repositoryService.ValidateToken(token, refresh);
|
||||||
.Where(u => u.uid == uid)
|
|
||||||
|
var user = await _dbContext.User
|
||||||
|
.Where(u => u.uid == validateToken.uid)
|
||||||
.Select(u => new User
|
.Select(u => new User
|
||||||
{
|
{
|
||||||
uid = u.uid,
|
uid = u.uid,
|
||||||
|
@ -56,10 +60,22 @@ public class UserController : ControllerBase
|
||||||
login_date = u.login_date,
|
login_date = u.login_date,
|
||||||
type = u.type
|
type = u.type
|
||||||
})
|
})
|
||||||
.FirstOrDefault();
|
.FirstOrDefaultAsync();
|
||||||
|
|
||||||
|
// _logger.LogInformation($"CHECK!! {user.}");
|
||||||
|
|
||||||
return Ok(APIResponse.Send("000", "정상", user));
|
return Ok(APIResponse.Send("000", "정상", user));
|
||||||
}
|
}
|
||||||
|
catch (TokenException tokenEx)
|
||||||
|
{
|
||||||
|
_logger.LogInformation($"[로그인] : {tokenEx}");
|
||||||
|
return Ok(APIResponse.Send("001", "로그인 진행: 토큰에 문제가 있음",Empty));
|
||||||
|
}
|
||||||
|
catch (RefreshRevokeException refreshEx)
|
||||||
|
{
|
||||||
|
_logger.LogInformation($"[로그인] : {refreshEx}");
|
||||||
|
return Ok(APIResponse.Send("001", "로그인 진행: 리프레시 토큰 폐기",Empty));
|
||||||
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
return StatusCode(500, APIResponse.UnknownError());
|
return StatusCode(500, APIResponse.UnknownError());
|
||||||
|
@ -271,9 +287,10 @@ public class UserController : ControllerBase
|
||||||
{
|
{
|
||||||
return StatusCode(500, APIResponse.UnknownError());
|
return StatusCode(500, APIResponse.UnknownError());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// [HttpGet("set")]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -84,6 +84,9 @@ public class RepositoryService: IRepositoryService
|
||||||
}
|
}
|
||||||
|
|
||||||
//토큰 태울때는 인코딩 된 걸로 태워야지 원본꺼 태우면 데이터에 손상옵니다.
|
//토큰 태울때는 인코딩 된 걸로 태워야지 원본꺼 태우면 데이터에 손상옵니다.
|
||||||
|
/// <summary>
|
||||||
|
/// 실제로 엑세스 토큰과 리프레시 토큰으로 접근 하기 위한 메서드
|
||||||
|
/// </summary>
|
||||||
public async Task<ValidateToken> ValidateToken(string token, string refresh)
|
public async Task<ValidateToken> ValidateToken(string token, string refresh)
|
||||||
{
|
{
|
||||||
var principalToken = _jwtTokenService.ValidateToken(token);
|
var principalToken = _jwtTokenService.ValidateToken(token);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user