-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[BE/FEAT] 로그아웃 및 회원 탈퇴 구현
- Loading branch information
Showing
23 changed files
with
283 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
BE/eeos/src/main/java/com/blackcompany/eeos/auth/application/event/DeletedMemberEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.blackcompany.eeos.auth.application.event; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class DeletedMemberEvent { | ||
private final Long memberId; | ||
private final String token; | ||
|
||
private DeletedMemberEvent(Long memberId, String token) { | ||
this.memberId = memberId; | ||
this.token = token; | ||
} | ||
|
||
/** | ||
* 멤버 탈퇴 이벤트를 발행한다. | ||
* | ||
* @param memberId 회원 탈퇴를 원하는 멤버 id | ||
* @param token 회원 탈퇴 시 사용한 토큰 | ||
* @return | ||
*/ | ||
public static DeletedMemberEvent of(Long memberId, String token) { | ||
return new DeletedMemberEvent(memberId, token); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...rc/main/java/com/blackcompany/eeos/auth/application/event/DeletedMemberEventListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.blackcompany.eeos.auth.application.event; | ||
|
||
import com.blackcompany.eeos.auth.application.domain.token.TokenResolver; | ||
import com.blackcompany.eeos.auth.persistence.BlackAuthenticationRepository; | ||
import com.blackcompany.eeos.target.persistence.AttendRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Propagation; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.transaction.event.TransactionPhase; | ||
import org.springframework.transaction.event.TransactionalEventListener; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class DeletedMemberEventListener { | ||
private final AttendRepository attendRepository; | ||
private final BlackAuthenticationRepository blackAuthenticationRepository; | ||
private final TokenResolver tokenResolver; | ||
|
||
@Async | ||
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) | ||
@Transactional(propagation = Propagation.REQUIRES_NEW) | ||
public void handleDeletedProgram(DeletedMemberEvent event) { | ||
deleteTargetData(event.getMemberId()); | ||
saveUsedToken(event.getToken(), event.getMemberId()); | ||
} | ||
|
||
private void deleteTargetData(Long memberId) { | ||
attendRepository.deleteAllByMemberId(memberId); | ||
} | ||
|
||
private void saveUsedToken(String token, Long memberId) { | ||
blackAuthenticationRepository.save(token, memberId, getExpiredDate(token)); | ||
} | ||
|
||
private Long getExpiredDate(String token) { | ||
return tokenResolver.getExpiredDateByRefreshToken(token); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...src/main/java/com/blackcompany/eeos/auth/application/exception/TokenParsingException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.blackcompany.eeos.auth.application.exception; | ||
|
||
import com.blackcompany.eeos.common.exception.BusinessException; | ||
import org.springframework.http.HttpStatus; | ||
|
||
/** JWT 파싱 중 발생한 예외 */ | ||
public class TokenParsingException extends BusinessException { | ||
private static final String FAIL_CODE = "4007"; | ||
private String message; | ||
|
||
public TokenParsingException(Exception e) { | ||
super(FAIL_CODE, HttpStatus.BAD_REQUEST); | ||
message = e.getMessage(); | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return String.format("JWT 파싱 중 오류 발생: {}", message); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...src/main/java/com/blackcompany/eeos/auth/application/service/DeactivateMemberService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.blackcompany.eeos.auth.application.service; | ||
|
||
import com.blackcompany.eeos.auth.application.domain.token.TokenResolver; | ||
import com.blackcompany.eeos.auth.application.event.DeletedMemberEvent; | ||
import com.blackcompany.eeos.auth.application.usecase.LogOutUsecase; | ||
import com.blackcompany.eeos.auth.application.usecase.WithDrawUsecase; | ||
import com.blackcompany.eeos.auth.persistence.BlackAuthenticationRepository; | ||
import com.blackcompany.eeos.auth.persistence.OAuthMemberRepository; | ||
import com.blackcompany.eeos.member.persistence.MemberRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.ApplicationEventPublisher; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class DeactivateMemberService implements LogOutUsecase, WithDrawUsecase { | ||
private final BlackAuthenticationRepository blackAuthenticationRepository; | ||
private final TokenResolver tokenResolver; | ||
private final ApplicationEventPublisher eventPublisher; | ||
private final MemberRepository memberRepository; | ||
private final OAuthMemberRepository oAuthMemberRepository; | ||
|
||
@Override | ||
@Transactional | ||
public void logOut(final String token, final Long memberId) { | ||
saveUsedToken(token, memberId); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public void withDraw(final String token, final Long memberId) { | ||
if (isNotMember(memberId)) { | ||
return; | ||
} | ||
deleteMemberData(memberId); | ||
eventPublisher.publishEvent(DeletedMemberEvent.of(memberId, token)); | ||
} | ||
|
||
private void saveUsedToken(final String token, final Long memberId) { | ||
blackAuthenticationRepository.save(token, memberId, getExpiredToken(token)); | ||
} | ||
|
||
private Long getExpiredToken(final String token) { | ||
return tokenResolver.getExpiredDateByRefreshToken(token); | ||
} | ||
|
||
private boolean isNotMember(Long memberId) { | ||
return memberRepository.findById(memberId).isEmpty(); | ||
} | ||
|
||
private void deleteMemberData(Long memberId) { | ||
memberRepository.deleteById(memberId); | ||
oAuthMemberRepository.findByMemberId(memberId).ifPresent(oAuthMemberRepository::delete); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
BE/eeos/src/main/java/com/blackcompany/eeos/auth/application/usecase/LogOutUsecase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.blackcompany.eeos.auth.application.usecase; | ||
|
||
public interface LogOutUsecase { | ||
void logOut(String token, final Long memberId); | ||
} |
5 changes: 5 additions & 0 deletions
5
BE/eeos/src/main/java/com/blackcompany/eeos/auth/application/usecase/WithDrawUsecase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.blackcompany.eeos.auth.application.usecase; | ||
|
||
public interface WithDrawUsecase { | ||
void withDraw(String token, Long memberId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.