Skip to content

Commit df4fa12

Browse files
committed
fix : 이미 가입된 회원은 이메일 인증코드 전송 불가
1 parent c9f520c commit df4fa12

File tree

5 files changed

+17
-6
lines changed

5 files changed

+17
-6
lines changed

backend/src/main/java/com/backend/domain/user/controller/AuthController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public ApiResponse<String> verifyAuthCode(@RequestBody VerifyRequest request)
7070
//인증 성공시
7171
return ApiResponse.success("이메일 인증 성공");
7272
}else{
73-
return ApiResponse.error(ErrorCode.Email_verify_Failed);
73+
return ApiResponse.error(ErrorCode.EMAIL_VERIFY_FAILED);
7474
}
7575

7676
}
@@ -117,7 +117,7 @@ public ApiResponse<LoginResponse> login(
117117

118118
return ApiResponse.success(new LoginResponse(new UserDto(user)));
119119
}else{
120-
return ApiResponse.error(ErrorCode.Login_Failed);
120+
return ApiResponse.error(ErrorCode.LOGIN_FAILED);
121121
}
122122
}
123123

@@ -151,7 +151,7 @@ public ApiResponse<String> logout(
151151
}
152152

153153

154-
return ApiResponse.success("success");
154+
return ApiResponse.success("로그아웃 되었습니다.");
155155
}
156156

157157

backend/src/main/java/com/backend/domain/user/repository/UserRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ public interface UserRepository extends JpaRepository<User,Long> {
1212

1313
@Query("SELECT u FROM User u WHERE u.email = :email AND u.deleted = true")
1414
Optional<User> findByEmailIncludeDeleted(@Param("email") String email);
15+
16+
boolean existsByEmail(String email);
1517
}

backend/src/main/java/com/backend/domain/user/service/EmailService.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
@RequiredArgsConstructor
1616
@Transactional
1717
public class EmailService {
18+
private final UserRepository userRepository;
1819
private final JavaMailSender javaMailSender;
1920
private final RedisUtil redisUtil;
2021

@@ -35,6 +36,13 @@ private String createCode(){
3536
* @param email
3637
*/
3738
public void sendEmail(String email) throws MessagingException {
39+
//이미 회원가입된 email이면 예외 발생
40+
boolean existsByEmail = userRepository.existsByEmail(email);
41+
if(existsByEmail){
42+
System.out.println("이미 회원가입된 이메일 입니다.");
43+
throw new BusinessException(ErrorCode.ALREADY_REGISTERED_EMAIL);
44+
}
45+
3846
String authCode = createCode();
3947
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
4048
// true: 멀티파트 메시지(HTML 등) 활성화, "utf-8": 인코딩 설정

backend/src/main/java/com/backend/domain/user/service/JwtService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public String login(@NotBlank(message = "이메일은 필수 입력값 입니다
2929
//email에 대응하는 비밀번호가 맞다면 jwt토큰 발급
3030
return jwtUtil.createToken(user.getEmail(), user.getName(), user.getId());
3131
}else{
32-
throw new BusinessException(ErrorCode.Login_Failed);
32+
throw new BusinessException(ErrorCode.LOGIN_FAILED);
3333
}
3434
}
3535

backend/src/main/java/com/backend/global/exception/ErrorCode.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ public enum ErrorCode {
1414
MISSING_REQUEST_PARAMETER("CMN005", HttpStatus.BAD_REQUEST, "필수 요청 파라미터가 누락되었습니다."),
1515

1616
// ========== user 도메인 에러 ==========
17-
Login_Failed("U001", HttpStatus.BAD_REQUEST, "로그인에 실패했습니다."),
18-
Email_verify_Failed("U002", HttpStatus.BAD_REQUEST, "이메일 인증코드가 일치하지 않습니다"),
17+
LOGIN_FAILED("U001", HttpStatus.BAD_REQUEST, "로그인에 실패했습니다."),
18+
EMAIL_VERIFY_FAILED("U002", HttpStatus.BAD_REQUEST, "이메일 인증코드가 일치하지 않습니다"),
1919
NAME_NOT_FOUND("U003", HttpStatus.NOT_FOUND, "이름이 입력되지 않았습니다."),
2020
PASSWORD_NOT_FOUND("U004", HttpStatus.NOT_FOUND, "비밀번호가 입력되지 않았습니다."),
2121
PASSWORD_NOT_EQUAL("U005", HttpStatus.BAD_REQUEST, "비밀번호 확인이 일치하지 않습니다."),
2222
EMAIL_NOT_FOUND("U006", HttpStatus.NOT_FOUND, "해당 이메일은 없는 계정입니다.") ,
23+
ALREADY_REGISTERED_EMAIL("U007", HttpStatus.BAD_REQUEST, "이미 회원가입된 이메일입니다."),
2324

2425
// ========== analysis 도메인 에러 ==========
2526
INVALID_GITHUB_URL("A001", HttpStatus.BAD_REQUEST, "올바른 GitHub 저장소 URL이 아닙니다."),

0 commit comments

Comments
 (0)