From 08ba589fad3a70e5fa1e68851651097554ce50b3 Mon Sep 17 00:00:00 2001 From: seulgi99 Date: Mon, 29 Jul 2024 19:07:30 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EB=B3=80=EA=B2=BD=EC=82=AC?= =?UTF-8?q?=ED=95=AD=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UnivEmailVerificationService.java | 21 +++---------------- .../domain/HongikUnivEmailValidator.java | 15 +++++++++++++ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/gdschongik/gdsc/domain/email/application/UnivEmailVerificationService.java b/src/main/java/com/gdschongik/gdsc/domain/email/application/UnivEmailVerificationService.java index 834e4614a..562cae910 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/email/application/UnivEmailVerificationService.java +++ b/src/main/java/com/gdschongik/gdsc/domain/email/application/UnivEmailVerificationService.java @@ -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; @@ -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) { @@ -43,7 +42,7 @@ private EmailVerificationTokenDto getEmailVerificationToken(String verificationT final Optional univEmailVerification = getUnivEmailVerificationFromRedis(emailVerificationTokenDto.memberId()); - validateUnivEmailVerification(univEmailVerification, verificationToken); + hongikUnivEmailValidator.validateUnivEmailVerification(univEmailVerification, verificationToken); return emailVerificationTokenDto; } @@ -51,18 +50,4 @@ private EmailVerificationTokenDto getEmailVerificationToken(String verificationT private Member getMemberById(Long id) { return memberRepository.findById(id).orElseThrow(() -> new CustomException(ErrorCode.MEMBER_NOT_FOUND)); } - - /** - * redis 안의 존재하는 메일인증 정보로 검증 - * 1. 토큰이 비었는데 인증하려할 시 에러 (인증메일을 보내지 않았거나, 만료된 경우) - * 2. 토큰이 redis에 저장된 토큰과 다르면 만료되었다는 에러 (메일 여러번 보낸 경우) - */ - private void validateUnivEmailVerification( - Optional 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); - } - } } diff --git a/src/main/java/com/gdschongik/gdsc/domain/email/domain/HongikUnivEmailValidator.java b/src/main/java/com/gdschongik/gdsc/domain/email/domain/HongikUnivEmailValidator.java index 3b8115886..7abd0ccdc 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/email/domain/HongikUnivEmailValidator.java +++ b/src/main/java/com/gdschongik/gdsc/domain/email/domain/HongikUnivEmailValidator.java @@ -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 { @@ -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 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); + } + } }