feat: user수정
This commit is contained in:
parent
8c49670a89
commit
15399f1e6b
@ -135,7 +135,6 @@ public class UserController {
|
|||||||
if (jwtUtil.checkToken(request.getHeader("Authorization"))) {
|
if (jwtUtil.checkToken(request.getHeader("Authorization"))) {
|
||||||
log.info("사용 가능한 토큰!!!");
|
log.info("사용 가능한 토큰!!!");
|
||||||
try {
|
try {
|
||||||
// 로그인 사용자 정보.
|
|
||||||
User member = userService.userInfo(userId);
|
User member = userService.userInfo(userId);
|
||||||
resultMap.put("userInfo", member);
|
resultMap.put("userInfo", member);
|
||||||
status = HttpStatus.OK;
|
status = HttpStatus.OK;
|
||||||
@ -153,12 +152,16 @@ public class UserController {
|
|||||||
return new ResponseEntity<Map<String, Object>>(resultMap, status);
|
return new ResponseEntity<Map<String, Object>>(resultMap, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/logout/{userId}")
|
@GetMapping("/logout")
|
||||||
|
|
||||||
public ResponseEntity<?> removeToken(@PathVariable ("userId") @Parameter(description = "로그아웃 할 회원의 아이디.", required = true) Long userId) {
|
public ResponseEntity<?> removeToken(HttpServletRequest request) {
|
||||||
Map<String, Object> resultMap = new HashMap<>();
|
Map<String, Object> resultMap = new HashMap<>();
|
||||||
HttpStatus status = HttpStatus.ACCEPTED;
|
HttpStatus status = HttpStatus.ACCEPTED;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
String token = request.getHeader("Authorization");
|
||||||
|
Long userId = Long.parseLong(jwtUtil.getUserId(token));
|
||||||
|
|
||||||
userService.deleteRefreshToken(userId);
|
userService.deleteRefreshToken(userId);
|
||||||
status = HttpStatus.OK;
|
status = HttpStatus.OK;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -174,14 +177,10 @@ public class UserController {
|
|||||||
public ResponseEntity<?> refreshToken(HttpServletRequest request,HttpServletResponse response)
|
public ResponseEntity<?> refreshToken(HttpServletRequest request,HttpServletResponse response)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
// System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@");
|
|
||||||
// System.out.println(user.getUserId());
|
|
||||||
Map<String, Object> resultMap = new HashMap<>();
|
Map<String, Object> resultMap = new HashMap<>();
|
||||||
HttpStatus status = HttpStatus.ACCEPTED;
|
HttpStatus status = HttpStatus.ACCEPTED;
|
||||||
|
|
||||||
// String token = request.getHeader("refreshToken");
|
|
||||||
|
|
||||||
|
|
||||||
Cookie[] cookies = request.getCookies();
|
Cookie[] cookies = request.getCookies();
|
||||||
String token = null;
|
String token = null;
|
||||||
|
|
||||||
@ -194,17 +193,12 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Long userId = Long.parseLong(jwtUtil.getUserId(token));
|
Long userId = Long.parseLong(jwtUtil.getUserId(token));
|
||||||
/// System.out.println(userId);
|
|
||||||
/// System.out.println("리프레쉬 토큰 (쿠키에서 받은거 "+token);
|
|
||||||
// log.debug("token : {}, memberDto : {}", token, user);
|
|
||||||
// System.out.println(jwtUtil.checkToken(token));
|
|
||||||
if (jwtUtil.checkToken(token)) {
|
if (jwtUtil.checkToken(token)) {
|
||||||
|
|
||||||
// System.out.println(token);
|
|
||||||
// System.out.println(userService.getRefreshToken(userId));
|
|
||||||
//System.out.println("쿠키 토큰 , 디비 토큰 비교"+token.equals(userService.getRefreshToken(userId)));
|
|
||||||
if (token.equals(userService.getRefreshToken(userId))) {
|
if (token.equals(userService.getRefreshToken(userId))) {
|
||||||
System.out.println("!!");
|
|
||||||
String accessToken = jwtUtil.createAccessToken(String.valueOf(userId));
|
String accessToken = jwtUtil.createAccessToken(String.valueOf(userId));
|
||||||
String refreshToken = jwtUtil.createRefreshToken(String.valueOf(userId));
|
String refreshToken = jwtUtil.createRefreshToken(String.valueOf(userId));
|
||||||
|
|
||||||
@ -213,9 +207,9 @@ public class UserController {
|
|||||||
resultMap.put("access-token", accessToken);
|
resultMap.put("access-token", accessToken);
|
||||||
|
|
||||||
|
|
||||||
// 바뀐 리프레시db저장
|
|
||||||
userService.saveRefreshToken(userId,refreshToken);
|
userService.saveRefreshToken(userId,refreshToken);
|
||||||
// 쿠키 저장
|
|
||||||
Cookie refreshCookie = new Cookie("refresh-token", refreshToken);
|
Cookie refreshCookie = new Cookie("refresh-token", refreshToken);
|
||||||
refreshCookie.setPath("/");
|
refreshCookie.setPath("/");
|
||||||
refreshCookie.setHttpOnly(true);
|
refreshCookie.setHttpOnly(true);
|
||||||
|
@ -74,7 +74,7 @@ public class JWTUtil {
|
|||||||
System.out.println(token);
|
System.out.println(token);
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
log.error("Unexpected error while validating token: {}", e.getMessage());
|
log.error("Unexpected error while validating token: {}", e.getMessage());
|
||||||
return false;
|
throw new InvalidTokenException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,9 +110,6 @@ public class Controller {
|
|||||||
|
|
||||||
String roomName = lecture.getTitle();
|
String roomName = lecture.getTitle();
|
||||||
String participantName = userService.getUserName(userId);
|
String participantName = userService.getUserName(userId);
|
||||||
System.out.println(participantName);
|
|
||||||
|
|
||||||
System.out.println(participantName+randStr);
|
|
||||||
AccessToken token = new AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET);
|
AccessToken token = new AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET);
|
||||||
token.setName(participantName+randStr);
|
token.setName(participantName+randStr);
|
||||||
token.setIdentity(participantName+randStr);
|
token.setIdentity(participantName+randStr);
|
||||||
|
Loading…
Reference in New Issue
Block a user