From 09e2d1c2cf934af0e8cef7979d51341e7b3be894 Mon Sep 17 00:00:00 2001 From: JongbeomLee623 Date: Sat, 2 Nov 2024 04:42:38 +0900 Subject: [PATCH] =?UTF-8?q?BE:=20[fix]=20=EA=B4=80=EB=A6=AC=EC=9E=90=20?= =?UTF-8?q?=ED=9A=8C=EC=9B=90=EA=B0=80=EC=9E=85=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EA=B0=95=ED=99=94=20#1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/response/BaseResponseCode.java | 3 +++ .../fortune/eyesee/service/AdminService.java | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/backend/Eyesee/src/main/java/com/fortune/eyesee/common/response/BaseResponseCode.java b/src/backend/Eyesee/src/main/java/com/fortune/eyesee/common/response/BaseResponseCode.java index 61687ab..8ef0525 100644 --- a/src/backend/Eyesee/src/main/java/com/fortune/eyesee/common/response/BaseResponseCode.java +++ b/src/backend/Eyesee/src/main/java/com/fortune/eyesee/common/response/BaseResponseCode.java @@ -26,12 +26,15 @@ public enum BaseResponseCode { UNSUPPORTED_TOKEN("GL008", HttpStatus.BAD_REQUEST, "지원하지 않는 토큰입니다."), TOKEN_ERROR("GL009", HttpStatus.BAD_REQUEST, "토큰에 문제가 발생했습니다."), MALFORMED_TOKEN("GL010", HttpStatus.BAD_REQUEST, "토큰의 구조가 잘못되었습니다."), + INVALID_INPUT("GL011", HttpStatus.BAD_REQUEST, "입력이 잘못되었습니다."), // User Errors ALREADY_EXIST_USER("U0001", HttpStatus.CONFLICT, "이미 존재하는 사용자입니다"), WRONG_PASSWORD("U0002", HttpStatus.BAD_REQUEST, "비밀번호가 틀렸습니다."), NOT_FOUND_USER("U0003", HttpStatus.NOT_FOUND, "사용자를 찾을 수 없습니다."), NOT_EQUAL_PASSWORD("U0004", HttpStatus.BAD_REQUEST, "비밀번호가 일치하지 않습니다."), + WEAK_PASSWORD("U0005", HttpStatus.BAD_REQUEST, "비밀번호는 8자 이상이어야 합니다."), + INVALID_EMAIL_FORMAT("U0006", HttpStatus.BAD_REQUEST, "이메일 형식이 잘못되었습니다."), // 기타 추가 오류 코드 ... diff --git a/src/backend/Eyesee/src/main/java/com/fortune/eyesee/service/AdminService.java b/src/backend/Eyesee/src/main/java/com/fortune/eyesee/service/AdminService.java index 79f3948..32fc3ae 100644 --- a/src/backend/Eyesee/src/main/java/com/fortune/eyesee/service/AdminService.java +++ b/src/backend/Eyesee/src/main/java/com/fortune/eyesee/service/AdminService.java @@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service public class AdminService { @@ -19,15 +20,31 @@ public class AdminService { @Autowired private PasswordEncoder passwordEncoder; - // 회원가입 메서드 + @Transactional public Admin registerAdmin(AdminSignupRequestDTO adminSignupRequestDTO) { + if (adminSignupRequestDTO.getAdminEmail() == null || + adminSignupRequestDTO.getPassword() == null || + adminSignupRequestDTO.getPasswordConfirm() == null) { + throw new BaseException(BaseResponseCode.INVALID_INPUT); // 잘못된 입력 예외 처리 + } + if (adminRepository.findByAdminEmail(adminSignupRequestDTO.getAdminEmail()).isPresent()) { throw new BaseException(BaseResponseCode.ALREADY_EXIST_USER); // 이메일 중복 예외 처리 } + if (!adminSignupRequestDTO.getPassword().equals(adminSignupRequestDTO.getPasswordConfirm())) { throw new BaseException(BaseResponseCode.NOT_EQUAL_PASSWORD); // 비밀번호 불일치 예외 처리 } + if (adminSignupRequestDTO.getPassword().length() < 8) { + throw new BaseException(BaseResponseCode.WEAK_PASSWORD); // 비밀번호 강도 예외 처리 + } + + String emailPattern = "^[A-Za-z0-9+_.-]+@(.+)$"; + if (!adminSignupRequestDTO.getAdminEmail().matches(emailPattern)) { + throw new BaseException(BaseResponseCode.INVALID_EMAIL_FORMAT); // 잘못된 이메일 형식 예외 처리 + } + Admin admin = new Admin(); admin.setAdminEmail(adminSignupRequestDTO.getAdminEmail()); admin.setPassword(passwordEncoder.encode(adminSignupRequestDTO.getPassword()));