-
Notifications
You must be signed in to change notification settings - Fork 1
[BE/feat] auth 도메인 1차 제작 #46
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 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
cb788ed
feat(auth) : entity 작성, jwt 시작
rogrhrh f9d5a1d
feat(auth) : jwt 코드 작성
rogrhrh 13fad96
Merge branch 'dev' of https://github.com/prgrms-web-devcourse-final-p…
rogrhrh c7213be
feat(auth) : 컨트롤러, 서비스 작성 securityContext 사용
rogrhrh 2db7f5a
Merge branch 'dev' of https://github.com/prgrms-web-devcourse-final-p…
rogrhrh 7a1d0ca
feat(user) : 회원가입 구현
rogrhrh ca84bd5
Merge branch 'dev' of https://github.com/prgrms-web-devcourse-final-p…
rogrhrh e62be10
fix(auth) : test.yml에 jwt 정보가 없어서 테스트 통과 실패-> 추가함
rogrhrh faa7d2c
fix : ci 수정
rogrhrh f86a814
refactor(auth) : 중복코드 제거, 오류 수정, secure설정 yml로 제어
rogrhrh 36ff244
refactor(auth) : userid컬럼에 nullable 설정, 리프레시토큰 레포에 필요없는 함수 삭제
rogrhrh b1e08b5
refactor(auth) : 코드 통합, 매직넘버 상수화, 불필요한 주석 제거 등
rogrhrh d0fb52c
Merge branch 'dev' of https://github.com/prgrms-web-devcourse-final-p…
rogrhrh 54e5936
refactor(auth) : securityConfig 정리
rogrhrh 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,5 +41,6 @@ out/ | |
|
|
||
| ###custom### | ||
| application-secret.yml | ||
| .env | ||
| db_dev.mv.db | ||
| db_dev.trace.db | ||
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
326 changes: 268 additions & 58 deletions
326
src/main/java/back/kalender/domain/auth/controller/UserAuthController.java
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
46 changes: 46 additions & 0 deletions
46
src/main/java/back/kalender/domain/auth/entity/EmailVerification.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,46 @@ | ||
| package back.kalender.domain.auth.entity; | ||
|
|
||
| import back.kalender.global.common.entity.BaseEntity; | ||
| import jakarta.persistence.*; | ||
| import lombok.AccessLevel; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| // 이메일 인증 | ||
| @Entity | ||
| @Getter | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @Table( | ||
| name = "email_verifications", | ||
| indexes = { | ||
| @Index(name = "idx_user_id", columnList = "userId"), | ||
| @Index(name = "idx_code", columnList = "code") | ||
| } | ||
| ) | ||
| public class EmailVerification extends BaseEntity { | ||
|
|
||
| private Long userId; | ||
|
|
||
| @Column(nullable = false, length = 50) | ||
| private String code; | ||
|
|
||
| private boolean used; | ||
|
|
||
| @Column(nullable = false) | ||
| private LocalDateTime expiredAt; | ||
|
|
||
| public static EmailVerification create(Long userId, String code) { | ||
| EmailVerification ev = new EmailVerification(); | ||
| ev.userId = userId; | ||
| ev.code = code; | ||
| ev.used = false; | ||
| ev.expiredAt = LocalDateTime.now().plusMinutes(5); | ||
| return ev; | ||
| } | ||
|
|
||
| public void markUsed() { | ||
| this.used = true; | ||
| } | ||
| } |
46 changes: 46 additions & 0 deletions
46
src/main/java/back/kalender/domain/auth/entity/PasswordResetToken.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,46 @@ | ||
| package back.kalender.domain.auth.entity; | ||
|
|
||
| import back.kalender.global.common.entity.BaseEntity; | ||
| import jakarta.persistence.*; | ||
| import lombok.AccessLevel; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| // 비밀번호 변경 | ||
| @Entity | ||
| @Getter | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @Table( | ||
| name = "password_reset_tokens", | ||
| indexes = { | ||
| @Index(name = "idx_password_user_id", columnList = "userId"), | ||
| @Index(name = "idx_password_token", columnList = "token") | ||
| } | ||
| ) | ||
| public class PasswordResetToken extends BaseEntity { | ||
|
|
||
| private Long userId; | ||
|
|
||
| @Column(nullable = false, length = 500) | ||
| private String token; | ||
|
|
||
| private boolean used; | ||
|
|
||
| @Column(nullable = false) | ||
| private LocalDateTime expiredAt; | ||
|
|
||
| public static PasswordResetToken create(Long userId, String code) { | ||
| PasswordResetToken token = new PasswordResetToken(); | ||
| token.userId = userId; | ||
| token.token = code; | ||
| token.used = false; | ||
| token.expiredAt = LocalDateTime.now().plusMinutes(5); | ||
| return token; | ||
| } | ||
|
|
||
| public void markUsed() { | ||
| this.used = true; | ||
| } | ||
| } | ||
40 changes: 40 additions & 0 deletions
40
src/main/java/back/kalender/domain/auth/entity/RefreshToken.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,40 @@ | ||
| package back.kalender.domain.auth.entity; | ||
|
|
||
| import back.kalender.global.common.entity.BaseEntity; | ||
| import jakarta.persistence.*; | ||
| import lombok.AccessLevel; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| // 리프레시 토큰 | ||
| @Entity | ||
| @Getter | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @Table( | ||
| name = "refresh_tokens", | ||
| indexes = { | ||
| @Index(name = "idx_refresh_user_id", columnList = "userId"), | ||
| @Index(name = "idx_refresh_token", columnList = "token") | ||
| } | ||
| ) | ||
| public class RefreshToken extends BaseEntity { | ||
|
|
||
| private Long userId; | ||
|
|
||
| @Column(nullable = false, length = 1000) | ||
| private String token; | ||
|
|
||
| @Column(nullable = false) | ||
| private LocalDateTime expiredAt; | ||
|
|
||
| public static RefreshToken create(Long userId, String token, long ttlDays) { | ||
| RefreshToken rt = new RefreshToken(); | ||
| rt.userId = userId; | ||
| rt.token = token; | ||
| rt.expiredAt = LocalDateTime.now().plusDays(ttlDays); | ||
| return rt; | ||
| } | ||
|
|
||
| } |
Empty file.
12 changes: 12 additions & 0 deletions
12
src/main/java/back/kalender/domain/auth/repository/EmailVerificationRepository.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 back.kalender.domain.auth.repository; | ||
|
|
||
| import back.kalender.domain.auth.entity.EmailVerification; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| public interface EmailVerificationRepository extends JpaRepository<EmailVerification, Long> { | ||
| Optional<EmailVerification> findTopByUserIdOrderByCreatedAtDesc(Long userId); | ||
| Optional<EmailVerification> findByCode(String code); | ||
| void deleteByUserId(Long userId); | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/main/java/back/kalender/domain/auth/repository/PasswordResetTokenRepository.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 back.kalender.domain.auth.repository; | ||
|
|
||
| import back.kalender.domain.auth.entity.PasswordResetToken; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| public interface PasswordResetTokenRepository extends JpaRepository<PasswordResetToken, Long> { | ||
| Optional<PasswordResetToken> findByToken(String token); | ||
| void deleteByUserId(Long userId); | ||
| } |
13 changes: 13 additions & 0 deletions
13
src/main/java/back/kalender/domain/auth/repository/RefreshTokenRepository.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,13 @@ | ||
| package back.kalender.domain.auth.repository; | ||
|
|
||
| import back.kalender.domain.auth.entity.RefreshToken; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| public interface RefreshTokenRepository extends JpaRepository<RefreshToken, Long> { | ||
| Optional<RefreshToken> findByToken(String token); | ||
| List<RefreshToken> findAllByUserId(Long userId); | ||
|
||
| void deleteAllByUserId(Long userId); | ||
| } | ||
Empty file.
19 changes: 19 additions & 0 deletions
19
src/main/java/back/kalender/domain/auth/service/AuthService.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,19 @@ | ||
| package back.kalender.domain.auth.service; | ||
|
|
||
| import back.kalender.domain.auth.dto.request.*; | ||
| import back.kalender.domain.auth.dto.response.EmailStatusResponse; | ||
| import back.kalender.domain.auth.dto.response.UserLoginResponse; | ||
| import back.kalender.domain.auth.dto.response.VerifyEmailResponse; | ||
| import jakarta.servlet.http.HttpServletResponse; | ||
|
|
||
| public interface AuthService { | ||
| UserLoginResponse login(UserLoginRequest request, HttpServletResponse response); | ||
| void logout(String refreshToken); | ||
| void refreshToken(String refreshToken, HttpServletResponse response); | ||
| void sendPasswordResetEmail(UserPasswordResetSendRequest request); | ||
| void resetPassword(UserPasswordResetRequest request); | ||
| void sendVerifyEmail(VerifyEmailSendRequest request); | ||
| VerifyEmailResponse verifyEmail(VerifyEmailRequest request); | ||
| EmailStatusResponse getEmailStatus(Long userId); | ||
| } | ||
|
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nullable=false 명시해주시면 좋을 것 같습니다!