From 640b5fdf67fd7234dfbe01fc2c6ac165d35a72eb Mon Sep 17 00:00:00 2001 From: Mingyu Song <100754581+mikekks@users.noreply.github.com> Date: Tue, 30 Apr 2024 13:04:28 +0900 Subject: [PATCH] =?UTF-8?q?[CHORE]=20=EC=9D=B4=EB=A9=94=EC=9D=BC=20?= =?UTF-8?q?=EC=9D=B8=EC=A6=9D=20=ED=9B=84=20=EC=A4=91=EB=B3=B5=ED=9A=8C?= =?UTF-8?q?=EC=9B=90=20=EA=B0=80=EC=9E=85=20=EB=B0=A9=EC=A7=80=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20(#304)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [CHORE] 이메일 인증 후 중복회원 가입 방지 추가 * [CHORE] readOnly 추가 --- .../synk/meeteam/domain/auth/api/AuthController.java | 1 + .../domain/auth/exception/AuthExceptionType.java | 1 + .../meeteam/domain/auth/service/AuthService.java | 12 ++++++++++-- .../java/synk/meeteam/infra/mail/MailService.java | 6 ++++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/synk/meeteam/domain/auth/api/AuthController.java b/src/main/java/synk/meeteam/domain/auth/api/AuthController.java index dab90f07..a97e3f4d 100644 --- a/src/main/java/synk/meeteam/domain/auth/api/AuthController.java +++ b/src/main/java/synk/meeteam/domain/auth/api/AuthController.java @@ -90,6 +90,7 @@ public ResponseEntity signUp( AuthUserVo vo = AuthUserVo.of(user, user.getPlatformType(), user.getAuthority(), AuthType.SIGN_UP); AuthUserResponseDto.login responseDTO = jwtService.issueToken(vo); + mailService.deleteTemporaryUser(requestDto.emailCode()); return ResponseEntity.status(HttpStatus.CREATED).body(responseDTO); } diff --git a/src/main/java/synk/meeteam/domain/auth/exception/AuthExceptionType.java b/src/main/java/synk/meeteam/domain/auth/exception/AuthExceptionType.java index 1039b2f5..1930b29c 100644 --- a/src/main/java/synk/meeteam/domain/auth/exception/AuthExceptionType.java +++ b/src/main/java/synk/meeteam/domain/auth/exception/AuthExceptionType.java @@ -15,6 +15,7 @@ public enum AuthExceptionType implements ExceptionType { INVALID_ACCESS_TOKEN(HttpStatus.BAD_REQUEST, "유효하지 않은 액세스 토큰입니다."), INVALID_REFRESH_TOKEN(HttpStatus.BAD_REQUEST, "유효하지 않은 리프레시 토큰입니다."), INVALID_MAIL_SERVICE(HttpStatus.BAD_REQUEST, "메일 서비스를 이용할 수 없는 형식입니다."), + INVALID_ACCESS(HttpStatus.BAD_REQUEST, "올바르지 않는 요청입니다."), INVALID_VERIFY_MAIL(HttpStatus.BAD_REQUEST, "잘못된 이메일 코드 입니다."), INVALID_MAIL_REGEX(HttpStatus.BAD_REQUEST, "학교 도메인과 유저의 도메인이 다릅니다."), diff --git a/src/main/java/synk/meeteam/domain/auth/service/AuthService.java b/src/main/java/synk/meeteam/domain/auth/service/AuthService.java index a89cf120..8f454f02 100644 --- a/src/main/java/synk/meeteam/domain/auth/service/AuthService.java +++ b/src/main/java/synk/meeteam/domain/auth/service/AuthService.java @@ -1,10 +1,13 @@ package synk.meeteam.domain.auth.service; +import static synk.meeteam.domain.auth.exception.AuthExceptionType.INVALID_ACCESS; + import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import synk.meeteam.domain.auth.dto.request.AuthUserRequestDto; import synk.meeteam.domain.auth.dto.request.VerifyEmailRequestDto; +import synk.meeteam.domain.auth.exception.AuthException; import synk.meeteam.domain.auth.service.vo.AuthUserVo; import synk.meeteam.domain.common.department.entity.Department; import synk.meeteam.domain.common.department.repository.DepartmentRepository; @@ -72,7 +75,12 @@ public void updateUniversityInfo(VerifyEmailRequestDto requestDTO, String email) } @Transactional - public User createSocialUser(UserVO userVO, String nickName) { + public User createSocialUser(UserVO userVO, String nickname) { + // 닉네임 검사 + if(userRepository.findByNickname(nickname).isPresent()){ + throw new AuthException(INVALID_ACCESS); + } + University foundUniversity = universityRepository.findByIdOrElseThrowException( userVO.getUniversityId()); Department foundDepartment = departmentRepository.findByIdOrElseThrowException( @@ -81,7 +89,7 @@ public User createSocialUser(UserVO userVO, String nickName) { User newUser = User.builder() .universityEmail(userVO.getEmail()) .name(userVO.getName()) - .nickname(nickName) + .nickname(nickname) .phoneNumber(userVO.getPhoneNumber()) .admissionYear(userVO.getAdmissionYear()) .university(foundUniversity) diff --git a/src/main/java/synk/meeteam/infra/mail/MailService.java b/src/main/java/synk/meeteam/infra/mail/MailService.java index 16b97612..9dec00e5 100644 --- a/src/main/java/synk/meeteam/infra/mail/MailService.java +++ b/src/main/java/synk/meeteam/infra/mail/MailService.java @@ -137,4 +137,10 @@ public void sendApproveMail(Long postId, RecruitmentApplicant recruitmentApplica public UserVO verify(String emailCode) { return redisUserRepository.findByEmailCodeOrElseThrowException(emailCode); } + + @Transactional + public void deleteTemporaryUser(String emailCode) { + UserVO userVO = redisUserRepository.findByEmailCodeOrElseThrowException(emailCode); + redisUserRepository.delete(userVO); + } }