forked from AcaMate/AcaMate_API
1. 로그인 되었을 경우 화면 표기 변경 1.1. 사용자 이름 보내주기 1.2. 서버에서 직접적인 크라이언트 쿠키 저장이 아닌 서버는 뒤의 값으로 간섭하게 변경
176 lines
7.2 KiB
C#
176 lines
7.2 KiB
C#
using System.Security.Claims;
|
|
using Back.Program.Common.Auth;
|
|
using Back.Program.Common.Data;
|
|
using Back.Program.Common.Model;
|
|
using Back.Program.Models.Entities;
|
|
using Back.Program.Services.V1.Interfaces;
|
|
using Back.Program.Services.V1;
|
|
using Microsoft.AspNetCore.Http.HttpResults;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Back.Program.Controllers.V1
|
|
{
|
|
/// <summary>
|
|
/// USER는 사용자가 자신의 데이터를 보거나 만들거나 하는 등 직접 사용하는 경우에 사용
|
|
/// </summary>
|
|
[ApiController]
|
|
[Route("/api/v1/in/user")]
|
|
[ApiExplorerSettings(GroupName = "사용자")]
|
|
public class UserController : ControllerBase
|
|
{
|
|
private readonly ILogger<UserController> _logger;
|
|
private readonly IRepositoryService _repositoryService;
|
|
private readonly IUserService _userService;
|
|
|
|
public UserController(ILogger<UserController> logger,
|
|
IRepositoryService repositoryService, IUserService userService, IKakaoService kakaoService)
|
|
{
|
|
_logger = logger;
|
|
_repositoryService = repositoryService;
|
|
_userService = userService;
|
|
}
|
|
|
|
[HttpGet]
|
|
[CustomOperation("회원 정보 조회", "회원 정보 조회 (자기자신)", "사용자")]
|
|
public async Task<IActionResult> GetUserData(string token)
|
|
{
|
|
if (string.IsNullOrEmpty(token)) return BadRequest(APIResponse.InvalidInputError());
|
|
if (!ModelState.IsValid) return BadRequest(APIResponse.InvalidInputError());
|
|
string summary = _repositoryService.ReadSummary(typeof(UserController), "GetUserData");
|
|
|
|
var result = await _userService.GetUser(summary, token);
|
|
return Ok(result);
|
|
}
|
|
|
|
|
|
[HttpGet("login")]
|
|
[CustomOperation("SNS 로그인", "로그인 후 회원이 있는지 확인", "사용자")]
|
|
public async Task<IActionResult> Login(string accType, string snsId)
|
|
{
|
|
// API 동작 파라미터 입력 값 확인
|
|
if (string.IsNullOrEmpty(accType) && string.IsNullOrEmpty(snsId)) return BadRequest(APIResponse.InvalidInputError());
|
|
if (!ModelState.IsValid) return BadRequest(APIResponse.InvalidInputError());
|
|
|
|
string summary = _repositoryService.ReadSummary(typeof(UserController), "Login");
|
|
var result = await _userService.Login(summary, accType, snsId);
|
|
return Ok(result);
|
|
|
|
}
|
|
|
|
[HttpPost("register")]
|
|
[CustomOperation("회원 가입", "사용자 회원 가입", "사용자")]
|
|
public async Task<IActionResult> UserRegister([FromBody] UserAll request)
|
|
{
|
|
if (!ModelState.IsValid) return BadRequest(APIResponse.InvalidInputError());
|
|
string summary = _repositoryService.ReadSummary(typeof(UserController), "UserRegister");
|
|
|
|
var result = await _userService.Register(summary, request);
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpGet("logout")]
|
|
[CustomOperation("로그아웃", "사용자 로그아웃", "사용자")]
|
|
public async Task<IActionResult> Logout(string token)
|
|
{
|
|
if (string.IsNullOrEmpty(token)) return BadRequest(APIResponse.InvalidInputError());
|
|
if (!ModelState.IsValid) return BadRequest(APIResponse.InvalidInputError());
|
|
string summary = _repositoryService.ReadSummary(typeof(UserController), "Logout");
|
|
|
|
var result = await _userService.Logout(summary, token);
|
|
return Ok(result);
|
|
}
|
|
|
|
|
|
[HttpGet("cancel")]
|
|
[CustomOperation("회원 탈퇴", "사용자 탈퇴", "사용자")]
|
|
public async Task<IActionResult> Cancel(string token)
|
|
{
|
|
if (string.IsNullOrEmpty(token)) return BadRequest(APIResponse.InvalidInputError());
|
|
if (!ModelState.IsValid) return BadRequest(APIResponse.InvalidInputError());
|
|
string summary = _repositoryService.ReadSummary(typeof(UserController), "Cancel");
|
|
var result = await _userService.Cancel(summary, token);
|
|
return Ok(result);
|
|
}
|
|
|
|
|
|
[HttpGet("academy")]
|
|
[CustomOperation("학원 리스트 확인", "사용자가 등록된 학원 리스트 확인", "사용자")]
|
|
public async Task<IActionResult> GetAcademyData(string token)
|
|
{
|
|
if (string.IsNullOrEmpty(token)) return BadRequest(APIResponse.InvalidInputError());
|
|
if (!ModelState.IsValid) return BadRequest(APIResponse.InvalidInputError());
|
|
string summary = _repositoryService.ReadSummary(typeof(UserController), "ReadAcademyInfo");
|
|
|
|
var result = await _userService.GetAcademy(summary, token);
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpGet("auth/session")]
|
|
[CustomOperation("세션 정보 확인", "세션 정보 확인", "사용자")]
|
|
public async Task<IActionResult> GetSessionData()
|
|
{
|
|
string summary = _repositoryService.ReadSummary(typeof(UserController), "GetSessionData");
|
|
var result = await _userService.GetSessionData(summary);
|
|
return Ok(result);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
// 근데 회원 정보를 변경하는게 뭐뭐를 변경해야 하는지 아직 정해진게 없어서 이건 일단 보류
|
|
/*
|
|
[HttpGet("set")]
|
|
[CustomOperation("회원 정보 변경", "회원 정보 변경", "사혹자")]
|
|
public async Task<IActionResult> SetUserData(string token, string refresh) //, [FromBody])
|
|
{
|
|
if (string.IsNullOrEmpty(token) || string.IsNullOrEmpty(refresh))
|
|
return BadRequest(APIResponse.InvalidInputError());
|
|
if (!ModelState.IsValid) return BadRequest(APIResponse.InvalidInputError());
|
|
string summary = String.Empty;
|
|
|
|
try
|
|
{
|
|
summary = _repositoryService.ReadSummary(typeof(UserController), "Cancel");
|
|
|
|
|
|
// 여기서 애초에 토큰 관련 에러가 2개가 나오게 만들어져 있음
|
|
var validateToken = await _repositoryService.ValidateToken(token, refresh);
|
|
var user = await _dbContext.User.FirstOrDefaultAsync(u => u.uid == validateToken.uid);
|
|
|
|
}
|
|
catch (TokenException tokenEx)
|
|
{
|
|
return Ok(APIResponse.Send("101", $"[{summary}], 입력 받은 토큰의 문제", Empty));
|
|
}
|
|
catch (RefreshRevokeException refreshEx)
|
|
{
|
|
return Ok(APIResponse.Send("102", $"[{summary}], 폐기된 리프레시 토큰", Empty));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(500, APIResponse.UnknownError($"[{summary}], {ex.Message}"));
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
/*
|
|
string uid = "";
|
|
if (token == "System") uid = "System";
|
|
else {
|
|
if (string.IsNullOrEmpty(token) || string.IsNullOrEmpty(refresh)) return BadRequest(APIResponse.InvalidInputError());
|
|
if(!ModelState.IsValid) return BadRequest(APIResponse.InvalidInputError());
|
|
|
|
var validateToken = await _repositoryService.ValidateToken(token, refresh);
|
|
uid = validateToken.uid;
|
|
}
|
|
|
|
string summary = String.Empty;
|
|
try
|
|
{
|
|
summary = _repositoryService.ReadSummary(typeof(PushController), "GetUserData");
|
|
}
|
|
*/ |