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

[MS-204] sms 인증 화이트리스트 범위 수정 #110

Merged
merged 1 commit into from
Nov 20, 2024
Merged
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
@@ -1,6 +1,5 @@
package com.modutaxi.api.domain.sms.service;


import com.modutaxi.api.common.exception.BaseException;
import com.modutaxi.api.common.exception.errorcode.AuthErrorCode;
import com.modutaxi.api.common.exception.errorcode.SmsErrorCode;
Expand All @@ -13,7 +12,6 @@
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
@RequiredArgsConstructor
Expand All @@ -27,8 +25,8 @@ public class SmsService {
private Integer certCodeLength;
@Value("${sms.cert-sms-restriction-seconds}")
private Integer certSmsRestrictionSeconds;
@Value("${sms.cert-white-list-phone-numbers}")
private List<String> whiteListPhoneNumbers;
@Value("${sms.cert-white-list-phone-number-prefix}")
private String whiteListPhoneNumberPrefix;
@Value("${sms.cert-white-list-certification-code}")
private String whiteListCertificationCode;
@Value("${sms.cert-white-list-message-id}")
Expand All @@ -45,7 +43,8 @@ public Boolean sendCertificationCodeWithJwt(String memberId, String phoneNumber)

private Boolean sendCertificationCode(String key, String phoneNumber) {
String finalPhoneNumber = phoneNumber;
boolean isWhiteList = whiteListPhoneNumbers.stream().anyMatch(finalPhoneNumber::equals);
boolean isWhiteList = finalPhoneNumber.substring(0, 3).equals(whiteListPhoneNumberPrefix);
System.out.println(isWhiteList);
phoneNumber = checkPhoneNumberPattern(phoneNumber, isWhiteList);
SmsCertCodeEntity smsCertCodeEntity = redisSmsCertificationCodeRepository.findById(key);
if (smsCertCodeEntity != null) {
Expand All @@ -59,7 +58,8 @@ private Boolean sendCertificationCode(String key, String phoneNumber) {
String certificationCode = isWhiteList ? whiteListCertificationCode : CertificationCodeUtil.generateCertificationCode(certCodeLength);
String messageId = isWhiteList ? whiteListMessageId : smsAgencyUtil.sendOne(sender, phoneNumber, String.format("[모두의택시] 인증번호는 [%s]입니다.", certificationCode));
redisSmsCertificationCodeRepository.save(key, phoneNumber, certificationCode, messageId);
smsAgencyUtil.checkBalance();
if(!isWhiteList)
smsAgencyUtil.checkBalance();
return true;
}

Expand Down Expand Up @@ -89,7 +89,7 @@ public Boolean checkSmsCertificationCodeWithJwt(String memberId, String phoneNum

public Boolean checkSmsCertificationCode(String key, String phoneNumber, String certificationCode) {
String finalPhoneNumber = phoneNumber;
phoneNumber = checkPhoneNumberPattern(phoneNumber, whiteListPhoneNumbers.stream().anyMatch(finalPhoneNumber::equals));
phoneNumber = checkPhoneNumberPattern(phoneNumber, finalPhoneNumber.substring(0, 3).equals(whiteListPhoneNumberPrefix));
checkCertificationCodePattern(certificationCode);
SmsCertCodeEntity smsCertCodeEntity = redisSmsCertificationCodeRepository.findById(key);
if (smsCertCodeEntity == null) {
Expand Down