Skip to content

Commit

Permalink
refactor : 이메일 인증 API 상수 이름 수정, 랜덤 코드 생성 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
isprogrammingfun committed Nov 10, 2023
1 parent 0eda4d9 commit 2b8a30e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
@Service
@RequiredArgsConstructor
public class EmailSendService {
private static final int LENGTH = 6;
private static final String MESSAGE= "인증번호는 %s 입니다.";
private static final String TITLE = "KOA 이메일 인증";
private static final int CODE_LENGTH = 6;
private static final String MESSAGE_TEMPLATE = "인증번호는 %s 입니다.";
private static final String EMAIL_TITLE = "KOA 이메일 인증";

private final JavaMailSender emailSender;
private final RedisUtils redisUtils;

Expand All @@ -26,27 +27,22 @@ public class EmailSendService {

public void sendEmail(String email) {
String code = createCode();
SimpleMailMessage emailForm = createEmailForm(email, TITLE, String.format(MESSAGE, code));
String messageText = String.format(MESSAGE_TEMPLATE, code);
SimpleMailMessage emailForm = createEmailForm(email, EMAIL_TITLE, messageText);
emailSender.send(emailForm);
redisUtils.setDataExpire(email, code, authCodeExpirationMillis);
}

private String createCode() {
try {
Random random = SecureRandom.getInstanceStrong();
StringBuilder builder = new StringBuilder();
for (int i = 0; i < LENGTH; i++) {
builder.append(random.nextInt(10));
}
return builder.toString();
} catch (NoSuchAlgorithmException e) {
throw new CreateCodeException(Error.CREATE_CODE_FAIL);
Random random = new Random();
StringBuilder codeBuilder = new StringBuilder(CODE_LENGTH);
for (int i = 0; i < CODE_LENGTH; i++) {
codeBuilder.append(random.nextInt(10));
}
return codeBuilder.toString();
}

private SimpleMailMessage createEmailForm(String toEmail,
String title,
String text) {
private SimpleMailMessage createEmailForm(String toEmail, String title, String text) {
SimpleMailMessage message = new SimpleMailMessage();
message.setTo(toEmail);
message.setSubject(title);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class EmailVerificationUseCase {
private final MemberQueryService memberQueryService;

public void sendVerificationEmail(String email) {
memberQueryService.checkEmailExist(email);
emailSendService.sendEmail(email);
}

Expand Down

0 comments on commit 2b8a30e

Please sign in to comment.