Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CHORE] 이메일 인증 후 중복회원 가입 방지 추가 #304

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading