-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Kwoun Ki Ho <fingercut3822@gmail.com>
- Loading branch information
Showing
17 changed files
with
444 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ru/email/controller/dto/EmailRequest.java → ...mail/controller/request/EmailRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/com/cruru/email/controller/request/SendVerificationCodeRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.cruru.email.controller.request; | ||
|
||
import jakarta.validation.constraints.Email; | ||
import jakarta.validation.constraints.NotBlank; | ||
|
||
public record SendVerificationCodeRequest( | ||
@NotBlank | ||
String email | ||
) { | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
backend/src/main/java/com/cruru/email/controller/request/VerifyCodeRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.cruru.email.controller.request; | ||
|
||
import jakarta.validation.constraints.Email; | ||
import jakarta.validation.constraints.NotBlank; | ||
|
||
public record VerifyCodeRequest( | ||
@NotBlank | ||
String email, | ||
|
||
@NotBlank | ||
String verificationCode | ||
) { | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
...src/main/java/com/cruru/email/exception/badrequest/VerificationCodeMismatchException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.cruru.email.exception.badrequest; | ||
|
||
import com.cruru.advice.badrequest.BadRequestException; | ||
|
||
public class VerificationCodeMismatchException extends BadRequestException { | ||
|
||
private static final String MESSAGE = "인증 코드가 일치하지 않습니다."; | ||
|
||
public VerificationCodeMismatchException() { | ||
super(MESSAGE); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...src/main/java/com/cruru/email/exception/badrequest/VerificationCodeNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.cruru.email.exception.badrequest; | ||
|
||
import com.cruru.advice.badrequest.BadRequestException; | ||
|
||
public class VerificationCodeNotFoundException extends BadRequestException { | ||
|
||
private static final String MESSAGE = "인증 코드가 존재하지 않거나 만료되었습니다."; | ||
|
||
public VerificationCodeNotFoundException() { | ||
super(MESSAGE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
backend/src/main/java/com/cruru/email/service/EmailRedisClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.cruru.email.service; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class EmailRedisClient { | ||
|
||
private static final String REDIS_PREFIX = "email_verification:"; | ||
private static final long VERIFICATION_CODE_EXPIRATION = 10; | ||
|
||
private final RedisTemplate<String, String> redisTemplate; | ||
|
||
public void saveVerificationCode(String email, String verificationCode) { | ||
redisTemplate.opsForValue() | ||
.set(REDIS_PREFIX + email, verificationCode, VERIFICATION_CODE_EXPIRATION, TimeUnit.MINUTES); | ||
} | ||
|
||
public String getVerificationCode(String email) { | ||
return redisTemplate.opsForValue().get(REDIS_PREFIX + email); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
backend/src/main/java/com/cruru/email/util/EmailTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.cruru.email.util; | ||
|
||
public class EmailTemplate { | ||
|
||
public static String generateVerificationEmailContent(String verificationCode) { | ||
return """ | ||
<div style='font-family: Arial, sans-serif; padding: 20px; background-color: #ffffff; border: 1px solid #e0e0e0; max-width: 600px; margin: 0 auto;'> | ||
<div style='text-align: center; padding: 20px 0; background-color: #AA2298; color: white;'> | ||
<h1 style='margin: 0;'>크루루</h1> | ||
</div> | ||
<div style='padding: 30px; text-align: center;'> | ||
<h2 style='color: #333;'>[크루루] 인증 코드 안내</h2> | ||
<p style='font-size: 16px; color: #555;'>안녕하세요,</p> | ||
<p style='font-size: 16px; color: #555;'>아래 인증 코드를 입력해 주세요:</p> | ||
<div style='padding: 20px; background-color: #f0f0f0; border-radius: 10px; display: inline-block; margin: 20px 0;'> | ||
<span id='verificationCode' style='font-size: 32px; font-weight: bold; color: #333;'>%s</span> | ||
</div> | ||
<p style='font-size: 14px; color: #888;'>이 코드는 10분 후에 만료됩니다.</p> | ||
</div> | ||
<hr style='border: none; border-top: 1px solid #ddd; margin: 20px 0;'> | ||
<div style='padding: 20px; text-align: center; font-size: 12px; color: #888;'> | ||
<p>본 메일은 크루루 시스템에 의해 자동 발송되었습니다.</p> | ||
<p>© 2024 크루루. All Rights Reserved.</p> | ||
</div> | ||
</div> | ||
""".formatted(verificationCode); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
backend/src/main/java/com/cruru/email/util/VerificationCodeUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.cruru.email.util; | ||
|
||
import com.cruru.email.exception.badrequest.VerificationCodeMismatchException; | ||
import com.cruru.email.exception.badrequest.VerificationCodeNotFoundException; | ||
import java.util.Random; | ||
|
||
public class VerificationCodeUtil { | ||
|
||
private static final Random random = new Random(); | ||
private static final int CODE_LENGTH = 6; | ||
|
||
private VerificationCodeUtil() { | ||
} | ||
|
||
public static String generateVerificationCode() { | ||
return String.format("%0" + CODE_LENGTH + "d", random.nextInt((int) Math.pow(10, CODE_LENGTH))); | ||
} | ||
|
||
public static void verify(String storedVerificationCode, String inputVerificationCode) { | ||
if (storedVerificationCode == null) { | ||
throw new VerificationCodeNotFoundException(); | ||
} | ||
|
||
if (!storedVerificationCode.equals(inputVerificationCode)) { | ||
throw new VerificationCodeMismatchException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.