Skip to content

Commit

Permalink
feat: 회원 탈퇴 기능 구현 (#832)
Browse files Browse the repository at this point in the history
* feat: 회원 탈퇴 기능 구현

* style: 로그인 실패 로그 추가
  • Loading branch information
Arachneee authored Nov 18, 2024
1 parent 3f399aa commit c8bca31
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package haengdong.common.infrastructure;
package haengdong.common.auth.infrastructure;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
Expand All @@ -10,7 +10,6 @@
import haengdong.common.auth.application.AuthService;
import haengdong.common.exception.AuthenticationException;
import haengdong.common.exception.HaengdongErrorCode;
import haengdong.common.auth.infrastructure.AuthenticationExtractor;

@Slf4j
public class AdminInterceptor implements HandlerInterceptor {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package haengdong.common.infrastructure;
package haengdong.common.auth.infrastructure;

import static haengdong.common.infrastructure.AdminInterceptor.LOGIN_MEMBER_REQUEST;
import static haengdong.common.auth.infrastructure.AdminInterceptor.LOGIN_MEMBER_REQUEST;

import haengdong.common.auth.Login;
import jakarta.servlet.http.HttpServletRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import haengdong.common.auth.application.AuthService;
import haengdong.common.auth.infrastructure.AuthenticationExtractor;
import haengdong.common.auth.infrastructure.JwtTokenProvider;
import haengdong.common.infrastructure.AdminInterceptor;
import haengdong.common.auth.infrastructure.AdminInterceptor;
import haengdong.common.properties.CorsProperties;
import haengdong.common.properties.JwtProperties;
import haengdong.event.application.EventService;
Expand Down
11 changes: 7 additions & 4 deletions server/src/main/java/haengdong/user/application/KakaoClient.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package haengdong.user.application;

import haengdong.common.exception.HaengdongErrorCode;
import haengdong.common.exception.HaengdongException;
import haengdong.user.application.response.KakaoTokenResponse;
import haengdong.user.config.KakaoProperties;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestClient;
import haengdong.user.application.response.KakaoTokenResponse;
import haengdong.user.config.KakaoProperties;
import haengdong.common.exception.HaengdongErrorCode;
import haengdong.common.exception.HaengdongException;

@Slf4j
@RequiredArgsConstructor
@EnableConfigurationProperties(KakaoProperties.class)
@Component
Expand All @@ -36,6 +38,7 @@ public KakaoTokenResponse join(String code, String redirectUri) {
.retrieve()
.body(KakaoTokenResponse.class);
} catch (Exception e) {
log.info("로그인 실패 : {}", code);
throw new HaengdongException(HaengdongErrorCode.KAKAO_LOGIN_FAIL, e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import com.auth0.jwt.JWT;
import com.auth0.jwt.interfaces.DecodedJWT;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import haengdong.user.application.response.KakaoTokenResponse;

@Slf4j
@RequiredArgsConstructor
@Service
public class KakaoUserService {
Expand All @@ -23,6 +25,8 @@ public Long joinByKakao(String code, String redirectUri) {
String memberNumber = decodedJWT.getSubject();
String nickname = decodedJWT.getClaim(NICKNAME_KEY).asString();

log.info("로그인 성공 : {}, {}", code, nickname);

return userService.join(memberNumber, nickname);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public String findNicknameById(Long id) {
return user.getNickname();
}

@Transactional
public void withdraw(Long id) {
userRepository.deleteById(id);
}

private User getUser(Long id) {
return userRepository.findById(id)
.orElseThrow(() -> new HaengdongException(HaengdongErrorCode.PASSWORD_INVALID));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.http.ResponseCookie;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand Down Expand Up @@ -63,6 +64,12 @@ public ResponseEntity<Void> kakaoLogin(
.build();
}

@DeleteMapping("/api/admin/users")
public ResponseEntity<Void> deleteUser(@Login Long userId) {
userService.withdraw(userId);
return ResponseEntity.ok().build();
}

private ResponseCookie createResponseCookie(String token) {
return ResponseCookie.from(authService.getTokenName(), token)
.httpOnly(cookieProperties.httpOnly())
Expand All @@ -73,5 +80,4 @@ private ResponseCookie createResponseCookie(String token) {
.maxAge(cookieProperties.maxAge())
.build();
}

}

0 comments on commit c8bca31

Please sign in to comment.