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); + } }