Skip to content

Commit

Permalink
PH-110 비밀번호 재설정시 이메일 유효성 체크 api 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
w-seok committed Apr 16, 2024
1 parent e6e550e commit dcfa38a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.peoplehere.api.common.controller;

import static com.peoplehere.shared.common.util.PatternUtils.*;
import static org.springframework.http.HttpStatus.*;

import java.security.Principal;

Expand All @@ -23,6 +24,7 @@
import com.peoplehere.api.common.data.request.MailVerifyRequestDto;
import com.peoplehere.api.common.data.response.MailVerificationResponseDto;
import com.peoplehere.api.common.exception.ClientBindException;
import com.peoplehere.api.common.exception.DuplicateException;
import com.peoplehere.api.common.service.AccountService;
import com.peoplehere.api.common.service.VerifyService;
import com.peoplehere.shared.common.data.request.AlarmConsentRequestDto;
Expand Down Expand Up @@ -109,15 +111,34 @@ public ResponseEntity<String> modifyPassword(@Validated @RequestBody PasswordReq
* @return
*/
@GetMapping("/email/check")
public ResponseEntity<String> checkEmail(@RequestParam String email) {
public ResponseEntity<String> checkEmailDuplicate(@RequestParam String email) {
if (!EMAIL_PATTERN.matcher(email).matches()) {
log.error("이메일 형식 오류: {}", email);
return ResponseEntity.badRequest().build();
}
accountService.checkEmail(email);
if (accountService.checkEmailExist(email)) {
throw new DuplicateException(email);
}
return ResponseEntity.ok().body("success");
}

/**
* 비밀번호 재설정을 위한 이메일 유효성(db에 존재하는지) 체크
* @param email 이메일
* @return
*/
@GetMapping("/email/exist")
public ResponseEntity<String> checkEmailExist(@RequestParam String email) {
if (!EMAIL_PATTERN.matcher(email).matches()) {
log.error("이메일 형식 오류: {}", email);
return ResponseEntity.badRequest().build();
}
if (accountService.checkEmailExist(email)) {
return ResponseEntity.ok().body("success");
}
return ResponseEntity.status(NOT_FOUND).body("해당 이메일: [%s]이 존재하지 않습니다".formatted(email));
}

/**
* 알람 동의 여부를 저장함
* @param requestDto 알람 동의 여부
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ public void updatePassword(PasswordRequestDto requestDto) {
}

@Transactional(readOnly = true)
public void checkEmail(String email) {
public boolean checkEmailExist(String email) {
if (accountRepository.existsByEmail(email)) {
throw new DuplicateException(email);
return true;
}
return false;
}

@Transactional
Expand Down

0 comments on commit dcfa38a

Please sign in to comment.