Skip to content

Commit

Permalink
release: โœจ Demo Account for Review (#239)
Browse files Browse the repository at this point in the history
* chore: add admin account environment

* feat: admin mode phone verification

* chore: add default value to admin env
  • Loading branch information
psychology50 authored Feb 8, 2025
1 parent b245fef commit c260063
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
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

0 comments on commit c260063

Please sign in to comment.