Skip to content

Commit

Permalink
refactor: 변경사항 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
seulgi99 committed Jul 29, 2024
1 parent de7697e commit 08ba589
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.gdschongik.gdsc.domain.email.application;

import static com.gdschongik.gdsc.global.exception.ErrorCode.EMAIL_NOT_SENT;
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 @@ -25,6 +23,7 @@ public class UnivEmailVerificationService {
private final EmailVerificationTokenUtil emailVerificationTokenUtil;
private final MemberRepository memberRepository;
private final UnivEmailVerificationRepository univEmailVerificationRepository;
private final HongikUnivEmailValidator hongikUnivEmailValidator;

@Transactional
public void verifyMemberUnivEmail(UnivEmailVerificationRequest request) {
Expand All @@ -43,26 +42,12 @@ private EmailVerificationTokenDto getEmailVerificationToken(String verificationT
final Optional<UnivEmailVerification> univEmailVerification =
getUnivEmailVerificationFromRedis(emailVerificationTokenDto.memberId());

validateUnivEmailVerification(univEmailVerification, verificationToken);
hongikUnivEmailValidator.validateUnivEmailVerification(univEmailVerification, verificationToken);

return emailVerificationTokenDto;
}

private Member getMemberById(Long id) {
return memberRepository.findById(id).orElseThrow(() -> new CustomException(ErrorCode.MEMBER_NOT_FOUND));
}

/**
* redis 안의 존재하는 메일인증 정보로 검증
* 1. 토큰이 비었는데 인증하려할 시 에러 (인증메일을 보내지 않았거나, 만료된 경우)
* 2. 토큰이 redis에 저장된 토큰과 다르면 만료되었다는 에러 (메일 여러번 보낸 경우)
*/
private void validateUnivEmailVerification(
Optional<UnivEmailVerification> optionalUnivEmailVerification, String currentToken) {
if (optionalUnivEmailVerification.isEmpty()) {
throw new CustomException(EMAIL_NOT_SENT);
} else if (!optionalUnivEmailVerification.get().getVerificationToken().equals(currentToken)) {
throw new CustomException(EXPIRED_EMAIL_VERIFICATION_TOKEN);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import com.gdschongik.gdsc.global.annotation.DomainService;
import com.gdschongik.gdsc.global.exception.CustomException;
import java.util.Optional;

@DomainService
public class HongikUnivEmailValidator {
Expand All @@ -23,4 +24,18 @@ public void validateSendUnivEmailVerificationLink(String email, boolean isUnivEm
throw new CustomException(UNIV_EMAIL_ALREADY_SATISFIED);
}
}

/**
* redis 안의 존재하는 메일인증 정보로 검증
* 1. 토큰이 비었는데 인증하려할 시 에러 (인증메일을 보내지 않았거나, 만료된 경우)
* 2. 토큰이 redis에 저장된 토큰과 다르면 만료되었다는 에러 (메일 여러번 보낸 경우)
*/
public void validateUnivEmailVerification(
Optional<UnivEmailVerification> optionalUnivEmailVerification, String currentToken) {
if (optionalUnivEmailVerification.isEmpty()) {
throw new CustomException(EMAIL_NOT_SENT);
} else if (!optionalUnivEmailVerification.get().getVerificationToken().equals(currentToken)) {
throw new CustomException(EXPIRED_EMAIL_VERIFICATION_TOKEN);
}
}
}

0 comments on commit 08ba589

Please sign in to comment.