forked from AcaMate/AcaMate_API
[♻️] 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)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(token)) return null;
|
||||
|
|
|
@ -25,6 +25,7 @@ public class PushController : ControllerBase
|
|||
public IActionResult GetPushData()
|
||||
{
|
||||
return Ok("SEND");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -39,51 +40,67 @@ public class PushController : ControllerBase
|
|||
/// <response code="500">Internal server error occurred.</response>
|
||||
/// <response code="999">Service unavailable.</response>
|
||||
[HttpPost("send")]
|
||||
[CustomOperation("푸시전송", "저장된 양식으로, 사용자에게 푸시를 전송한다.", "푸시")]
|
||||
[CustomOperation("푸시전송", "저장된 양식으로, 사용자에게 푸시를 전송한다.(로컬 테스트 불가)", "푸시")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(APIResponseStatus<object>))]
|
||||
public async Task<IActionResult> SendPush(string deviceToken, [FromBody] Payload? payload)
|
||||
{
|
||||
|
||||
if (string.IsNullOrWhiteSpace(deviceToken))
|
||||
{
|
||||
var inputError = APIResponse.InvalidInputError;
|
||||
// inputError.status.message = "Deviece Toekn 오류";
|
||||
return StatusCode(500,inputError);
|
||||
}
|
||||
|
||||
|
||||
if (payload == null)
|
||||
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;
|
||||
// inputError.status.message = "payload 입력 오류";
|
||||
return StatusCode(500,inputError);
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
uri = "https://api.push.apple.com/";
|
||||
p12Path = "/src/private/AM_Push.p12";
|
||||
// p12Path = "private/AM_Push.p12";
|
||||
}
|
||||
|
||||
if (isDevelopment)
|
||||
{
|
||||
return new ApnsPushService(
|
||||
"https://api.sandbox.push.apple.com/",
|
||||
"/src/private/AM_Push_Sandbox.p12",
|
||||
pw, topic
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new ApnsPushService(
|
||||
"https://api.push.apple.com/",
|
||||
"/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 인스턴스 생성
|
||||
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)
|
||||
{
|
||||
return Ok(APIResponse.Success());
|
||||
|
|
|
@ -38,27 +38,43 @@ public class UserController : ControllerBase
|
|||
|
||||
[HttpGet]
|
||||
[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
|
||||
{
|
||||
var user = _dbContext.User
|
||||
.Where(u => u.uid == uid)
|
||||
.Select(u => new User
|
||||
{
|
||||
uid = u.uid,
|
||||
name = u.name,
|
||||
auto_login_yn = u.auto_login_yn,
|
||||
birth = u.birth,
|
||||
device_id = u.device_id,
|
||||
login_date = u.login_date,
|
||||
type = u.type
|
||||
})
|
||||
.FirstOrDefault();
|
||||
var validateToken = await _repositoryService.ValidateToken(token, refresh);
|
||||
|
||||
var user = await _dbContext.User
|
||||
.Where(u => u.uid == validateToken.uid)
|
||||
.Select(u => new User
|
||||
{
|
||||
uid = u.uid,
|
||||
name = u.name,
|
||||
auto_login_yn = u.auto_login_yn,
|
||||
birth = u.birth,
|
||||
device_id = u.device_id,
|
||||
login_date = u.login_date,
|
||||
type = u.type
|
||||
})
|
||||
.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)
|
||||
{
|
||||
|
@ -271,8 +287,9 @@ public class UserController : ControllerBase
|
|||
{
|
||||
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)
|
||||
{
|
||||
var principalToken = _jwtTokenService.ValidateToken(token);
|
||||
|
|
Loading…
Reference in New Issue
Block a user