From 7cd8d329a25c424ae377ae402390b143a2c4136e Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 17 Jan 2024 20:19:16 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20Member=20login=20&=20logout=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/controller/MemberController.java | 36 +++++++++++++++++++ .../member/service/MemberService.java | 5 +++ 2 files changed, 41 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/member/controller/MemberController.java diff --git a/src/main/java/com/prgrms/catchtable/member/controller/MemberController.java b/src/main/java/com/prgrms/catchtable/member/controller/MemberController.java new file mode 100644 index 00000000..06230af7 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/member/controller/MemberController.java @@ -0,0 +1,36 @@ +package com.prgrms.catchtable.member.controller; + +import com.prgrms.catchtable.common.login.LogIn; +import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.member.service.MemberService; +import java.net.URI; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/members") +public class MemberController { + + private final MemberService memberService; + + @GetMapping("/login/kakao") + public ResponseEntity loginRedirect(){ + HttpHeaders httpHeaders = new HttpHeaders(); + httpHeaders.setLocation(URI.create("/oauth2/authorization/kakao")); + return new ResponseEntity<>(httpHeaders, HttpStatus.MOVED_PERMANENTLY); + } + + @PostMapping("/logout") + public ResponseEntity logout(@LogIn Member member){ + memberService.logout(member.getEmail()); + return ResponseEntity.ok("logout"); + } + +} diff --git a/src/main/java/com/prgrms/catchtable/member/service/MemberService.java b/src/main/java/com/prgrms/catchtable/member/service/MemberService.java index 638c897c..9af6d339 100644 --- a/src/main/java/com/prgrms/catchtable/member/service/MemberService.java +++ b/src/main/java/com/prgrms/catchtable/member/service/MemberService.java @@ -34,6 +34,11 @@ public Token oauthLogin(OAuthAttribute attributes) { return createTotalToken(email); } + @Transactional + public void logout(String email){ + refreshTokenService.deleteRefreshToken(email); + } + private Token createTotalToken(String email) { Token totalToken = jwtTokenProvider.createToken(email, Role.MEMBER); refreshTokenService.saveRefreshToken(totalToken);