Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api: ✨ Demo Account for Review #239

Merged
merged 3 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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분간 유효)
*
Expand All @@ -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) {
Expand All @@ -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);
}
}
3 changes: 3 additions & 0 deletions pennyway-app-external-api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ jwt:
pennyway:
rabbitmq:
validate-connection: true
admin:
phone: ${PENNYWAY_ADMIN_PHONE:1234567890}
password: ${PENNYWAY_ADMIN_PASSWORD:1234567890}

---
spring:
Expand Down
Loading