File tree Expand file tree Collapse file tree 4 files changed +48
-4
lines changed
src/main/java/com/back/domain/user Expand file tree Collapse file tree 4 files changed +48
-4
lines changed Original file line number Diff line number Diff line change 11package com .back .domain .user .controller ;
22
3- import com .back .domain .user .dto .LoginRequest ;
4- import com .back .domain .user .dto .LoginResponse ;
5- import com .back .domain .user .dto .UserRegisterRequest ;
6- import com .back .domain .user .dto .UserResponse ;
3+ import com .back .domain .user .dto .*;
74import com .back .domain .user .service .AuthService ;
85import com .back .global .common .dto .RsData ;
96import jakarta .servlet .http .HttpServletRequest ;
@@ -50,6 +47,19 @@ public ResponseEntity<RsData<UserResponse>> verifyEmail(
5047 ));
5148 }
5249
50+ // 인증 메일 재발송
51+ @ PostMapping ("/email-verification/resend" )
52+ public ResponseEntity <RsData <Void >> resendVerificationEmail (
53+ @ Valid @ RequestBody ResendVerificationRequest request
54+ ) {
55+ authService .resendVerificationEmail (request .email ());
56+ return ResponseEntity
57+ .ok (RsData .success (
58+ "인증 메일이 재발송되었습니다." ,
59+ null
60+ ));
61+ }
62+
5363 // 로그인
5464 @ PostMapping ("/login" )
5565 public ResponseEntity <RsData <LoginResponse >> login (
Original file line number Diff line number Diff line change 1+ package com .back .domain .user .dto ;
2+
3+ import jakarta .validation .constraints .Email ;
4+ import jakarta .validation .constraints .NotBlank ;
5+
6+ public record ResendVerificationRequest (
7+ @ NotBlank @ Email String email
8+ ) {
9+ }
Original file line number Diff line number Diff line change 1010public interface UserRepository extends JpaRepository <User , Long > {
1111 boolean existsByUsername (String username );
1212 boolean existsByEmail (String email );
13+ Optional <User > findByEmail (String email );
1314 Optional <User > findByUsername (String username );
1415 Optional <User > findByProviderAndProviderId (String provider , String providerId );
1516}
Original file line number Diff line number Diff line change @@ -123,6 +123,30 @@ public UserResponse verifyEmail(String token) {
123123 return UserResponse .from (user );
124124 }
125125
126+ /**
127+ * 인증 메일 재발송 서비스
128+ * 1. 사용자 조회
129+ * 2. 이미 활성화된 사용자면 예외 처리
130+ * 3. 새로운 이메일 인증 토큰 생성
131+ * 4. 이메일 발송
132+ */
133+ public void resendVerificationEmail (String email ) {
134+ // 사용자 조회
135+ User user = userRepository .findByEmail (email )
136+ .orElseThrow (() -> new CustomException (ErrorCode .USER_NOT_FOUND ));
137+
138+ // 이미 활성화된 사용자면 예외 처리
139+ if (user .getUserStatus () == UserStatus .ACTIVE ) {
140+ throw new CustomException (ErrorCode .ALREADY_VERIFIED );
141+ }
142+
143+ // 새로운 이메일 인증 토큰 생성
144+ String emailToken = tokenService .createEmailVerificationToken (user .getId ());
145+
146+ // 이메일 발송
147+ emailService .sendVerificationEmail (user .getEmail (), emailToken );
148+ }
149+
126150 /**
127151 * 로그인 서비스
128152 * 1. 사용자 조회 및 비밀번호 검증
You can’t perform that action at this time.
0 commit comments