Skip to content

Commit

Permalink
Merge pull request #121 from sharemindteam/feature/120-recovery-email…
Browse files Browse the repository at this point in the history
…-duplicate

feat: 복구 이메일 중복 확인 구현
  • Loading branch information
letskuku authored Feb 19, 2024
2 parents 398cd61 + 8d31589 commit e1f7742
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public interface AuthService {

void checkDuplicateEmail(String email);

Boolean checkDuplicateRecoveryEmail(String email);

Boolean getPasswordMatched(AuthGetPasswordMatchRequest authGetPasswordMatchRequest, Long customerId);

void updatePassword(AuthUpdatePasswordRequest authUpdatePasswordRequest, Long customerId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ public class AuthServiceImpl implements AuthService {
@Transactional
@Override
public void signUp(AuthSignUpRequest authSignUpRequest) {
if (customerRepository.existsByEmailAndIsActivatedIsTrue(authSignUpRequest.getEmail()) || customerRepository.existsByEmailAndIsActivatedIsTrue(authSignUpRequest.getRecoveryEmail())) {
if (customerRepository.existsByEmailAndIsActivatedIsTrue(authSignUpRequest.getEmail())) {
throw new AuthException(AuthErrorCode.EMAIL_ALREADY_EXIST, authSignUpRequest.getEmail());
} else if (customerRepository.existsByRecoveryEmailAndIsActivatedIsTrue(
authSignUpRequest.getRecoveryEmail())) {
throw new AuthException(AuthErrorCode.RECOVERY_EMAIL_ALREADY_EXIST,
authSignUpRequest.getRecoveryEmail());
}

Customer customer = authSignUpRequest.toEntity(passwordEncoder.encode(authSignUpRequest.getPassword()));
Expand Down Expand Up @@ -89,6 +93,11 @@ public void checkDuplicateEmail(String email) {
}
}

@Override
public Boolean checkDuplicateRecoveryEmail(String email) {
return customerRepository.existsByRecoveryEmailAndIsActivatedIsTrue(email);
}

@Override
public Boolean getPasswordMatched(AuthGetPasswordMatchRequest authGetPasswordMatchRequest, Long customerId) {
Customer customer = customerRepository.findByCustomerIdAndIsActivatedIsTrue(customerId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
@Getter
public enum AuthErrorCode {

EMAIL_ALREADY_EXIST(HttpStatus.BAD_REQUEST, "이미 회원으로 등록된 이메일입니다."),
EMAIL_ALREADY_EXIST(HttpStatus.CONFLICT, "이미 회원으로 등록된 이메일입니다."),
RECOVERY_EMAIL_ALREADY_EXIST(HttpStatus.CONFLICT, "이미 등록된 복구 이메일입니다."),
INVALID_RECOVERY_EMAIL(HttpStatus.BAD_REQUEST, "로그인 이메일과 동일한 이메일은 복구 이메일로 사용할 수 없습니다."),
INVALID_PASSWORD(HttpStatus.BAD_REQUEST, "비밀번호가 일치하지 않습니다."),
DUPLICATE_PASSWORD(HttpStatus.BAD_REQUEST, "새 비밀번호가 현재 비밀번호와 동일합니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ public class AuthController {
@Operation(summary = "회원가입", description = "customer 생성")
@ApiResponses({
@ApiResponse(responseCode = "201", description = "회원가입 성공"),
@ApiResponse(responseCode = "400", description = "1. 이미 가입된 이메일 주소\n 2. 올바르지 않은 이메일/비밀번호/전화번호 형식\n 3. 로그인 이메일과 복구 이메일 주소가 동일",
@ApiResponse(responseCode = "400", description = "1. 올바르지 않은 이메일/비밀번호/전화번호 형식\n 2. 로그인 이메일과 복구 이메일 주소가 동일",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = CustomExceptionResponse.class))
),
@ApiResponse(responseCode = "409", description = "1. 이미 가입된 이메일 주소\n 2. 이미 등록된 복구 이메일 주소",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = CustomExceptionResponse.class))
)
Expand Down Expand Up @@ -148,7 +152,7 @@ public ResponseEntity<Void> signOut(@Valid @RequestBody AuthSignOutRequest authS
schema = @Schema(implementation = CustomExceptionResponse.class))
)
})
@PatchMapping("find-id")
@PatchMapping("/find-id")
public ResponseEntity<Void> findIdByRecoveryEmail(@Valid @RequestBody AuthFindRequest authFindRequest) {
authService.sendIdByRecoveryEmail(authFindRequest);
return ResponseEntity.ok().build();
Expand All @@ -167,9 +171,22 @@ public ResponseEntity<Void> findIdByRecoveryEmail(@Valid @RequestBody AuthFindRe
schema = @Schema(implementation = CustomExceptionResponse.class))
)
})
@PatchMapping("find-password")
@PatchMapping("/find-password")
public ResponseEntity<Void> findPasswordByRecoveryEmail(@Valid @RequestBody AuthFindRequest authFindRequest) {
authService.updateAndSendPasswordByRecoveryEmail(authFindRequest);
return ResponseEntity.ok().build();
}

@Operation(summary = "복구 이메일 중복 확인",
description = """
- 복구 이메일 중복 확인
- 중복된 이메일 있으면 true, 없으면 false
- 주소 형식: /api/v1/auth/recovery-email?email=aaa@gmail.com""")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "확인 성공")
})
@GetMapping("/recovery-email")
public ResponseEntity<Boolean> checkDuplicateRecoveryEmail(@RequestParam String email) {
return ResponseEntity.ok(authService.checkDuplicateRecoveryEmail(email));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
public interface CustomerRepository extends JpaRepository<Customer, Long> {
Boolean existsByEmailAndIsActivatedIsTrue(String email);

Boolean existsByRecoveryEmailAndIsActivatedIsTrue(String recoveryEmail);

Optional<Customer> findByEmailAndIsActivatedIsTrue(String email);

Optional<Customer> findByCustomerIdAndIsActivatedIsTrue(Long id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
.authorizeHttpRequests( // TODO 여기 더 나은 방법이 있을 것 같은데 일단 동작은 하니까 두고 추후에 리팩토링...ㅠㅠ
requests -> requests.requestMatchers("/error", "/swagger-ui/**", "/api-docs/**",
"/api/v1/auth/signUp", "/api/v1/auth/signIn", "/api/v1/auth/reissue",
"/api/v1/auth/find-id", "/api/v1/auth/find-password", "/api/v1/emails/**").permitAll()
"/api/v1/auth/find-id", "/api/v1/auth/find-password", "/api/v1/auth/recovery-email/**", "/api/v1/emails/**").permitAll()
.requestMatchers("/api/v1/counselors/all/**", "/api/v1/searchWords/results", "/api/v1/reviews/all/**").permitAll()
.requestMatchers("/index.html", "/favicon.ico", "/chat/**", "/customer.html",
"/counselor.html").permitAll()
Expand Down

0 comments on commit e1f7742

Please sign in to comment.