Skip to content

Commit

Permalink
[CHORE] 이메일 인증 후 중복회원 가입 방지 추가 (#304)
Browse files Browse the repository at this point in the history
* [CHORE] 이메일 인증 후 중복회원 가입 방지 추가

* [CHORE] readOnly 추가
  • Loading branch information
mikekks authored Apr 30, 2024
1 parent b39bc5e commit 640b5fd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public ResponseEntity<AuthUserResponseDto.login> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, "학교 도메인과 유저의 도메인이 다릅니다."),

Expand Down
12 changes: 10 additions & 2 deletions src/main/java/synk/meeteam/domain/auth/service/AuthService.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/synk/meeteam/infra/mail/MailService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 640b5fd

Please sign in to comment.