Skip to content

Commit 90897aa

Browse files
authored
refactor : 이메일 검증 API (#364)
* refactor : 이메일 검증 API // rc, prod endpoint구분 * refactor : 이메일 검증 API // yml파일 중복부분 수정 * refactor : 이메일 검증 API // yml파일 중복부분 수정2트 * refactor : 이메일 검증 API // 피드백 반영 * refactor : 이메일 검증 API // 피드백 반영22
1 parent 8f8ff29 commit 90897aa

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/main/java/com/gamzabat/algohub/feature/user/service/EmailService.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.concurrent.CompletableFuture;
44

5+
import org.springframework.beans.factory.annotation.Value;
56
import org.springframework.mail.javamail.JavaMailSender;
67
import org.springframework.mail.javamail.MimeMessageHelper;
78
import org.springframework.retry.annotation.Recover;
@@ -24,9 +25,11 @@
2425
@RequiredArgsConstructor
2526
@Slf4j
2627
public class EmailService {
28+
29+
@Value("${spring.profiles.active:dev}")
30+
private String activeProfile;
31+
2732
private static final String FROM_ADDRESS = "noreply@algohub.kr";
28-
private static final String EMAIL_VERIFICATION_CLIENT_ENDPOINT = "https://algohub.kr/signup";
29-
private static final String RESET_PASSWORD_CLIENT_ENDPOINT = "https://algohub.kr/reset-password";
3033
private final JavaMailSender mailSender;
3134
private final TemplateEngine templateEngine;
3235

@@ -51,7 +54,6 @@ private void sendMail(String recipient, EmailType type, String content) {
5154
try {
5255
MimeMessage message = mailSender.createMimeMessage();
5356
MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
54-
5557
helper.setTo(recipient);
5658
helper.setFrom(FROM_ADDRESS);
5759
helper.setSubject(getEmailSubject(type));
@@ -76,19 +78,21 @@ private String getEmailContent(EmailType type, String token) {
7678
switch (type) {
7779
case RESET_PASSWORD: {
7880
Context context = new Context();
81+
String clientEndpoint = getClientEndpoint("reset-password");
7982
context.setVariable("title", EmailTemplateStrings.RESET_PASSWORD_TITLE);
8083
context.setVariable("content", EmailTemplateStrings.RESET_PASSWORD_CONTENT);
8184
context.setVariable("button", EmailTemplateStrings.RESET_PASSWORD_BUTTON);
82-
context.setVariable("url", RESET_PASSWORD_CLIENT_ENDPOINT + "?token=" + token);
85+
context.setVariable("url", clientEndpoint + "?token=" + token);
8386
return templateEngine.process("email-template", context);
8487
}
8588

8689
case EMAIL_VALIDATION:
8790
Context context = new Context();
91+
String clientEndpoint = getClientEndpoint("signup");
8892
context.setVariable("title", EmailTemplateStrings.EMAIL_VALIDATION_TITLE);
8993
context.setVariable("content", EmailTemplateStrings.EMAIL_VALIDATION_CONTENT);
9094
context.setVariable("button", EmailTemplateStrings.EMAIL_VALIDATION_BUTTON);
91-
context.setVariable("url", EMAIL_VERIFICATION_CLIENT_ENDPOINT + "?token=" + token);
95+
context.setVariable("url", clientEndpoint + "?token=" + token);
9296
return templateEngine.process("email-template", context);
9397
default:
9498
throw new IllegalArgumentException("LOGIC ERROR : Unreachable code block");
@@ -102,4 +106,14 @@ private String getEmailSubject(EmailType type) {
102106
default -> throw new IllegalArgumentException("LOGIC ERROR : Unreachable code block");
103107
};
104108
}
109+
110+
private String getClientEndpoint(String apiType) {
111+
112+
if ("prod".equals(activeProfile)) {
113+
return ("https://algohub.kr/" + apiType);
114+
} else {
115+
return ("https://rc.algohub.kr/" + apiType);
116+
}
117+
118+
}
105119
}

src/main/resources/application.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ spring:
1313
rc:
1414
- dev
1515
- common
16-
1716
---
1817
spring:
1918
config:
@@ -23,19 +22,16 @@ spring:
2322
driver-class-name: com.mysql.cj.jdbc.Driver
2423
username: ${mysql_username}
2524
password: ${mysql_password}
26-
2725
jpa:
2826
database: mysql
2927
database-platform: org.hibernate.dialect.MySQLDialect
3028
open-in-view: false
3129
hibernate:
3230
ddl-auto: update
33-
3431
servlet:
3532
multipart:
3633
max-file-size: 5MB
3734
max-request-size: 6MB
38-
3935
data:
4036
redis:
4137
host: localhost
@@ -64,7 +60,6 @@ cloud:
6460
credentials:
6561
access-key: ${aws_access_key}
6662
secret-key: ${aws_secret_key}
67-
6863
logging:
6964
config: classpath:logback-spring.xml
7065
server:

0 commit comments

Comments
 (0)