From c26006348ba8c3aecdb96af2837fb9662d607302 Mon Sep 17 00:00:00 2001 From: JaeSeo Yang <96044622+psychology50@users.noreply.github.com> Date: Sat, 8 Feb 2025 22:31:13 +0900 Subject: [PATCH] =?UTF-8?q?release:=20=E2=9C=A8=20Demo=20Account=20for=20R?= =?UTF-8?q?eview=20(#239)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: add admin account environment * feat: admin mode phone verification * chore: add default value to admin env --- .../service/PhoneVerificationService.java | 43 ++++++++++++++++++- .../src/main/resources/application.yml | 3 ++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/auth/service/PhoneVerificationService.java b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/auth/service/PhoneVerificationService.java index cada8e77b..8b1c4845e 100644 --- a/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/auth/service/PhoneVerificationService.java +++ b/pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/auth/service/PhoneVerificationService.java @@ -6,8 +6,8 @@ import kr.co.pennyway.domain.context.account.service.PhoneCodeService; import kr.co.pennyway.domain.domains.phone.type.PhoneCodeKeyType; import kr.co.pennyway.infra.common.event.PushCodeEvent; -import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Service; @@ -16,11 +16,25 @@ @Slf4j @Service -@RequiredArgsConstructor public class PhoneVerificationService { private final PhoneCodeService phoneCodeService; private final ApplicationEventPublisher eventPublisher; + private final String adminPhone; + private final String adminCode; + + public PhoneVerificationService( + PhoneCodeService phoneCodeService, + ApplicationEventPublisher eventPublisher, + @Value("${pennyway.admin.phone}") String adminPhone, + @Value("${pennyway.admin.password}") String adminCode + ) { + this.phoneCodeService = phoneCodeService; + this.eventPublisher = eventPublisher; + this.adminPhone = adminPhone; + this.adminCode = adminCode; + } + /** * 휴대폰 번호로 인증 코드를 발송하고 캐싱한다. (5분간 유효) * @@ -47,6 +61,11 @@ public PhoneVerificationDto.PushCodeRes sendCode(PhoneVerificationDto.PushCodeRe */ public Boolean isValidCode(PhoneVerificationDto.VerifyCodeReq request, PhoneCodeKeyType codeType) throws IllegalArgumentException { String expectedCode; + + if (byPassVerificationCode(request.phone(), request.code(), codeType)) { + return Boolean.TRUE; + } + try { expectedCode = phoneCodeService.readByPhone(request.phone(), codeType); } catch (IllegalArgumentException e) { @@ -67,4 +86,24 @@ private String issueVerificationCode() { } return sb.toString(); } + + private boolean byPassVerificationCode(String phone, String code, PhoneCodeKeyType codeType) { + if (codeType.equals(PhoneCodeKeyType.FIND_PASSWORD) || codeType.equals(PhoneCodeKeyType.FIND_USERNAME)) { + return Boolean.FALSE; + } + + if (isAdminPhone(phone)) { + if (!adminCode.equals(code)) + throw new PhoneVerificationException(PhoneVerificationErrorCode.IS_NOT_VALID_CODE); + log.info("관리자 전화번호로 인증되었습니다."); + + return Boolean.TRUE; + } + + return Boolean.FALSE; + } + + private boolean isAdminPhone(String phone) { + return adminPhone.equals(phone); + } } diff --git a/pennyway-app-external-api/src/main/resources/application.yml b/pennyway-app-external-api/src/main/resources/application.yml index 38762156d..35b0fca07 100644 --- a/pennyway-app-external-api/src/main/resources/application.yml +++ b/pennyway-app-external-api/src/main/resources/application.yml @@ -16,6 +16,9 @@ jwt: pennyway: rabbitmq: validate-connection: true + admin: + phone: ${PENNYWAY_ADMIN_PHONE:1234567890} + password: ${PENNYWAY_ADMIN_PASSWORD:1234567890} --- spring: