From 630f2c416b09ac7f2c4a1e3a2d585b93519b6519 Mon Sep 17 00:00:00 2001 From: mikekks Date: Mon, 29 Apr 2024 22:49:58 +0900 Subject: [PATCH 1/2] =?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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../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 | 8 +++++++- 4 files changed, 19 insertions(+), 3 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..cf3f5ced 100644 --- a/src/main/java/synk/meeteam/infra/mail/MailService.java +++ b/src/main/java/synk/meeteam/infra/mail/MailService.java @@ -133,8 +133,14 @@ public void sendApproveMail(Long postId, RecruitmentApplicant recruitmentApplica } - @Transactional(readOnly = true) + @Transactional public UserVO verify(String emailCode) { return redisUserRepository.findByEmailCodeOrElseThrowException(emailCode); } + + @Transactional + public void deleteTemporaryUser(String emailCode) { + UserVO userVO = redisUserRepository.findByEmailCodeOrElseThrowException(emailCode); + redisUserRepository.delete(userVO); + } } From f846a29f3bc4ae0a80e29001138701f76b86fc17 Mon Sep 17 00:00:00 2001 From: mikekks Date: Mon, 29 Apr 2024 22:51:44 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[CHORE]=20readOnly=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/synk/meeteam/infra/mail/MailService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/synk/meeteam/infra/mail/MailService.java b/src/main/java/synk/meeteam/infra/mail/MailService.java index cf3f5ced..9dec00e5 100644 --- a/src/main/java/synk/meeteam/infra/mail/MailService.java +++ b/src/main/java/synk/meeteam/infra/mail/MailService.java @@ -133,7 +133,7 @@ public void sendApproveMail(Long postId, RecruitmentApplicant recruitmentApplica } - @Transactional + @Transactional(readOnly = true) public UserVO verify(String emailCode) { return redisUserRepository.findByEmailCodeOrElseThrowException(emailCode); }