Skip to content
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 @@ -2,6 +2,7 @@

import java.util.concurrent.CompletableFuture;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.retry.annotation.Recover;
Expand All @@ -24,9 +25,11 @@
@RequiredArgsConstructor
@Slf4j
public class EmailService {

@Value("${spring.profiles.active:dev}")
private String activeProfile;

private static final String FROM_ADDRESS = "noreply@algohub.kr";
private static final String EMAIL_VERIFICATION_CLIENT_ENDPOINT = "https://algohub.kr/signup";
private static final String RESET_PASSWORD_CLIENT_ENDPOINT = "https://algohub.kr/reset-password";
private final JavaMailSender mailSender;
private final TemplateEngine templateEngine;

Expand All @@ -51,7 +54,6 @@ private void sendMail(String recipient, EmailType type, String content) {
try {
MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");

helper.setTo(recipient);
helper.setFrom(FROM_ADDRESS);
helper.setSubject(getEmailSubject(type));
Expand All @@ -76,19 +78,21 @@ private String getEmailContent(EmailType type, String token) {
switch (type) {
case RESET_PASSWORD: {
Context context = new Context();
String clientEndpoint = getClientEndpoint("reset-password");
context.setVariable("title", EmailTemplateStrings.RESET_PASSWORD_TITLE);
context.setVariable("content", EmailTemplateStrings.RESET_PASSWORD_CONTENT);
context.setVariable("button", EmailTemplateStrings.RESET_PASSWORD_BUTTON);
context.setVariable("url", RESET_PASSWORD_CLIENT_ENDPOINT + "?token=" + token);
context.setVariable("url", clientEndpoint + "?token=" + token);
return templateEngine.process("email-template", context);
}

case EMAIL_VALIDATION:
Context context = new Context();
String clientEndpoint = getClientEndpoint("signup");
context.setVariable("title", EmailTemplateStrings.EMAIL_VALIDATION_TITLE);
context.setVariable("content", EmailTemplateStrings.EMAIL_VALIDATION_CONTENT);
context.setVariable("button", EmailTemplateStrings.EMAIL_VALIDATION_BUTTON);
context.setVariable("url", EMAIL_VERIFICATION_CLIENT_ENDPOINT + "?token=" + token);
context.setVariable("url", clientEndpoint + "?token=" + token);
return templateEngine.process("email-template", context);
default:
throw new IllegalArgumentException("LOGIC ERROR : Unreachable code block");
Expand All @@ -102,4 +106,14 @@ private String getEmailSubject(EmailType type) {
default -> throw new IllegalArgumentException("LOGIC ERROR : Unreachable code block");
};
}

private String getClientEndpoint(String apiType) {

if ("prod".equals(activeProfile)) {
return ("https://algohub.kr/" + apiType);
} else {
return ("https://rc.algohub.kr/" + apiType);
}

}
}
5 changes: 0 additions & 5 deletions src/main/resources/application.yml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

???????????????

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ spring:
rc:
- dev
- common

---
spring:
config:
Expand All @@ -23,19 +22,16 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver
username: ${mysql_username}
password: ${mysql_password}

jpa:
database: mysql
database-platform: org.hibernate.dialect.MySQLDialect
open-in-view: false
hibernate:
ddl-auto: update

servlet:
multipart:
max-file-size: 5MB
max-request-size: 6MB

data:
redis:
host: localhost
Expand Down Expand Up @@ -64,7 +60,6 @@ cloud:
credentials:
access-key: ${aws_access_key}
secret-key: ${aws_secret_key}

logging:
config: classpath:logback-spring.xml
server:
Expand Down
Loading