-
Notifications
You must be signed in to change notification settings - Fork 0
feat(auth): 이메일 인증 및 리프레시 토큰 Redis 관리 구현 (#14, #15) #28
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0844e33
feat(auth): 토큰 갱신 엔드포인트 구현 (#14)
crolvlee 312687f
chore(config): application-local.properties 제거 및 .env 방식으로 통일 (#14)
crolvlee 2012f1b
feat(auth): 이메일 인증 코드 발송 및 검증 구현 (#14)
crolvlee 620b4d1
test(auth): 이메일 인증 서비스 및 회원가입 인증 검증 테스트 추가 (#14)
crolvlee 6e9bf33
feat(auth): 리프레시토큰을 redis에 저장하는 로직 추가, 로그아웃 구현 (#14)
crolvlee c050a07
test(auth): 리프레시 토큰 Redis 저장 및 갱신 로직 테스트 추가 (#14)
crolvlee e20d0c2
docs(auth): 리프레시 토큰 관리, 로그아웃 관련 문서 수정
crolvlee 2c804b8
Merge remote-tracking branch 'origin/develop' into feat/14-refreshtoken
crolvlee 8a19c54
fix(be): ErrorCode 두 번 선언된 문제 수정
crolvlee c15bd64
fix(auth): 이메일·토큰 요청 DTO에 입력값 검증 추가 (#14)
crolvlee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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/ssafy/salmanhae/model/dto/auth/EmailSendRequest.java
This file contains hidden or 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.ssafy.salmanhae.model.dto.auth; | ||
|
|
||
| import jakarta.validation.constraints.Email; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public class EmailSendRequest { | ||
| @NotBlank | ||
| private String email; | ||
| } | ||
17 changes: 17 additions & 0 deletions
17
backend/src/main/java/com/ssafy/salmanhae/model/dto/auth/EmailVerifyRequest.java
This file contains hidden or 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,17 @@ | ||
| package com.ssafy.salmanhae.model.dto.auth; | ||
|
|
||
| import jakarta.validation.constraints.Email; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.Pattern; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public class EmailVerifyRequest { | ||
| @NotBlank | ||
| private String email; | ||
|
|
||
| @NotBlank | ||
| @Pattern(regexp = "^\\d{6}$") | ||
| private String code; | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
10 changes: 10 additions & 0 deletions
10
backend/src/main/java/com/ssafy/salmanhae/model/dto/auth/RefreshRequest.java
This file contains hidden or 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,10 @@ | ||
| package com.ssafy.salmanhae.model.dto.auth; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public class RefreshRequest { | ||
| @NotBlank | ||
| private String refreshToken; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
11 changes: 11 additions & 0 deletions
11
backend/src/main/java/com/ssafy/salmanhae/model/dto/auth/RefreshResponse.java
This file contains hidden or 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,11 @@ | ||
| package com.ssafy.salmanhae.model.dto.auth; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public class RefreshResponse { | ||
| private String accessToken; | ||
| private String refreshToken; | ||
| } |
This file contains hidden or 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
50 changes: 50 additions & 0 deletions
50
backend/src/main/java/com/ssafy/salmanhae/service/auth/EmailVerificationService.java
This file contains hidden or 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,50 @@ | ||
| package com.ssafy.salmanhae.service.auth; | ||
|
|
||
| import com.ssafy.salmanhae.common.exception.ApiException; | ||
| import com.ssafy.salmanhae.common.exception.ErrorCode; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.data.redis.core.StringRedisTemplate; | ||
| import org.springframework.mail.SimpleMailMessage; | ||
| import org.springframework.mail.javamail.JavaMailSender; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import java.security.SecureRandom; | ||
| import java.time.Duration; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class EmailVerificationService { | ||
|
|
||
| private final StringRedisTemplate redisTemplate; | ||
| private final JavaMailSender mailSender; | ||
|
|
||
| @Value("${spring.mail.username}") | ||
| private String senderEmail; | ||
|
|
||
| private static final String VERIFY_PREFIX = "email:verify:"; | ||
| private static final String VERIFIED_PREFIX = "email:verified:"; | ||
|
|
||
| public void sendCode(String email) { | ||
| String code = String.format("%06d", new SecureRandom().nextInt(1_000_000)); | ||
| redisTemplate.opsForValue().set(VERIFY_PREFIX + email, code, Duration.ofMinutes(5)); | ||
|
|
||
| SimpleMailMessage message = new SimpleMailMessage(); | ||
| message.setFrom(senderEmail); | ||
| message.setTo(email); | ||
| message.setSubject("[살만해] 이메일 인증 코드"); | ||
| message.setText("인증 코드: " + code + "\n5분 내에 입력해주세요."); | ||
| mailSender.send(message); | ||
| } | ||
|
|
||
| public void verifyCode(String email, String code) { | ||
| String saved = redisTemplate.opsForValue().get(VERIFY_PREFIX + email); | ||
|
|
||
| if (saved == null || !saved.equals(code)) { | ||
| throw new ApiException(ErrorCode.INVALID_VERIFICATION_CODE); | ||
| } | ||
|
|
||
| redisTemplate.delete(VERIFY_PREFIX + email); | ||
| redisTemplate.opsForValue().set(VERIFIED_PREFIX + email, "true", Duration.ofMinutes(10)); | ||
| } | ||
| } |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.