Skip to content

Commit

Permalink
refactor: pr 변경사항 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
seulgi99 committed Jul 26, 2024
1 parent b8d1c98 commit 96caead
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import static com.gdschongik.gdsc.global.exception.ErrorCode.EXPIRED_EMAIL_VERIFICATION_TOKEN;

import com.gdschongik.gdsc.domain.email.dao.UnivEmailVerificationRepository;
import com.gdschongik.gdsc.domain.email.domain.HongikUnivEmailValidator;
import com.gdschongik.gdsc.domain.email.domain.UnivEmailVerification;
import com.gdschongik.gdsc.domain.email.dto.request.EmailVerificationTokenDto;
import com.gdschongik.gdsc.domain.email.dto.request.UnivEmailVerificationRequest;
Expand All @@ -27,8 +26,6 @@ public class UnivEmailVerificationService {
private final MemberRepository memberRepository;
private final UnivEmailVerificationRepository univEmailVerificationRepository;

private final HongikUnivEmailValidator hongikUnivEmailValidator;

@Transactional
public void verifyMemberUnivEmail(UnivEmailVerificationRequest request) {
EmailVerificationTokenDto emailVerificationToken = getEmailVerificationToken(request.token());
Expand All @@ -55,15 +52,16 @@ private Member getMemberById(Long id) {
return memberRepository.findById(id).orElseThrow(() -> new CustomException(ErrorCode.MEMBER_NOT_FOUND));
}

// redis 안의 존재하는 메일인증 정보로 검증
/**
* redis 안의 존재하는 메일인증 정보로 검증
* 1. 토큰이 비었는데 인증하려할 시 에러 (인증메일을 보내지 않았거나, 만료된 경우)
* 2. 토큰이 redis에 저장된 토큰과 다르면 만료되었다는 에러 (메일 여러번 보낸 경우)
*/
private void validateUnivEmailVerification(
Optional<UnivEmailVerification> optionalUnivEmailVerification, String currentToken) {
// 토큰이 비었는데 인증하려할 시 에러 (인증메일을 보내지 않았거나, 만료된 경우)
if (optionalUnivEmailVerification.isEmpty()) {
throw new CustomException(EMAIL_NOT_SENT);
}
// 토큰이 redis에 저장된 토큰과 다르면 만료되었다는 에러 (메일 여러번 보낸 경우)
else if (!optionalUnivEmailVerification.get().getVerificationToken().equals(currentToken)) {
} else if (!optionalUnivEmailVerification.get().getVerificationToken().equals(currentToken)) {
throw new CustomException(EXPIRED_EMAIL_VERIFICATION_TOKEN);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.gdschongik.gdsc.domain.auth.application.JwtService;
import com.gdschongik.gdsc.domain.auth.dto.AccessTokenDto;
import com.gdschongik.gdsc.domain.auth.dto.RefreshTokenDto;
import com.gdschongik.gdsc.domain.common.model.RequirementStatus;
import com.gdschongik.gdsc.domain.email.application.UnivEmailVerificationService;
import com.gdschongik.gdsc.domain.email.domain.UnivEmailVerification;
import com.gdschongik.gdsc.domain.member.dao.MemberRepository;
Expand Down Expand Up @@ -70,18 +69,7 @@ public MemberDashboardResponse getDashboard() {
final Member member = memberUtil.getCurrentMember();
final RecruitmentRound currentRecruitmentRound = onboardingRecruitmentService.findCurrentRecruitmentRound();
final Optional<Membership> myMembership = membershipService.findMyMembership(member, currentRecruitmentRound);

UnivVerificationStatus univVerificationStatus;

if (member.getAssociateRequirement().getUnivStatus() == RequirementStatus.SATISFIED) {
univVerificationStatus = UnivVerificationStatus.SATISFIED;
} else {
final Optional<UnivEmailVerification> univEmailVerification =
univEmailVerificationService.getUnivEmailVerificationFromRedis(member.getId());
univVerificationStatus = univEmailVerification.isPresent()
? UnivVerificationStatus.IN_PROGRESS
: UnivVerificationStatus.PENDING;
}
UnivVerificationStatus univVerificationStatus = determineUnivVerificationStatus(member);

return MemberDashboardResponse.of(
member, univVerificationStatus, currentRecruitmentRound, myMembership.orElse(null));
Expand All @@ -105,4 +93,16 @@ private void validateProfile() {
throw new CustomException(FORBIDDEN);
}
}

private UnivVerificationStatus determineUnivVerificationStatus(Member member) {
if (member.getAssociateRequirement().isUnivSatisfied()) {
return UnivVerificationStatus.SATISFIED;
} else {
final Optional<UnivEmailVerification> univEmailVerification =
univEmailVerificationService.getUnivEmailVerificationFromRedis(member.getId());
return univEmailVerification.isPresent()
? UnivVerificationStatus.IN_PROGRESS
: UnivVerificationStatus.PENDING;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void verifyInfo() {

// 데이터 전달 로직

private boolean isUnivSatisfied() {
public boolean isUnivSatisfied() {
return univStatus == SATISFIED;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public record MemberFullDto(
Long memberId,
@Schema(description = "권한", implementation = MemberRole.class) MemberRole role,
@Schema(description = "멤버 역할", implementation = MemberRole.class) MemberRole role,
@Schema(description = "회원정보", implementation = MemberBasicInfoDto.class) MemberBasicInfoDto basicInfo,
@Schema(description = "인증상태정보", implementation = MemberAssociateRequirementDto.class)
MemberAssociateRequirementDto associateRequirement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public enum ErrorCode {
UNIV_EMAIL_DOMAIN_MISMATCH(HttpStatus.BAD_REQUEST, "재학생 메일의 도메인이 맞지 않습니다."),
MESSAGING_EXCEPTION(HttpStatus.BAD_REQUEST, "수신자 이메일이 올바르지 않습니다."),
VERIFICATION_CODE_NOT_FOUND(HttpStatus.NOT_FOUND, "재학생 인증 코드가 존재하지 않습니다."),
EMAIL_NOT_SENT(HttpStatus.BAD_REQUEST, "이메일 인증 인증메일이 발송되지 않았습니다."),
EMAIL_NOT_SENT(HttpStatus.BAD_REQUEST, "재학생 인증 메일이 발송되지 않았습니다."),
EXPIRED_EMAIL_VERIFICATION_TOKEN(HttpStatus.BAD_REQUEST, "이메일 인증 토큰이 만료되었습니다."),
INVALID_EMAIL_VERIFICATION_TOKEN(HttpStatus.UNAUTHORIZED, "유효하지 않은 이메일 인증 토큰입니다."),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class 이메일검증시 {
@Test
void 인증토큰과_레디스에_존재하는_인증정보의_토큰이_다르면_실패한다() {
// given
// TODO: 아래 두줄 createGuestMember로 대체하기
Member member = memberRepository.save(Member.createGuestMember(OAUTH_ID));
logoutAndReloginAs(member.getId(), member.getRole());

Expand Down

0 comments on commit 96caead

Please sign in to comment.