Skip to content

Commit

Permalink
Merge pull request #97 from kookmin-sw/backend/develop/v3
Browse files Browse the repository at this point in the history
Backend/develop/v3
  • Loading branch information
J-Yong99 authored Apr 18, 2024
2 parents bc0c35e + bd69dd6 commit 0d310ca
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3,082 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,46 @@ public TokenResponseDTO.GetTempToken sendCode(AuthRequest.SendCode sendCode) {
log.info("sendCode.isSignUp : {}", sendCode.getIsSignUp());
if (sendCode.getIsSignUp().equals("true")) {
if(userRepository.existsByEmail(sendCode.getEmail())){
throw new AlreadyRegisteredEmailException("이미 가입된 이메일");
User user = userRepository.findByEmail(sendCode.getEmail()).orElseThrow(() -> new AlreadyRegisteredEmailException("미 가입된 이메일"));
if (user.getRole().equals(Role.ROLE_AUTH_USER)){
throw new AlreadyRegisteredEmailException("이미 가입된 이메일");
}
String randomCode = RandomStringUtils.randomAlphanumeric(6);
String email = sendCode.getEmail();
String code = mailService.sendMail(email, "Moment 인증코드", "인증코드 : " + randomCode);
if (Objects.equals(code, "success")) {
user.setVerificationCode(randomCode);
userService.save(user);
String accessToken = jwtTokenUtils.generateAccessToken(provider, iss, user.getId(), Role.ROLE_TEMP_USER);
return TokenResponseDTO.GetTempToken.builder()
.grantType("Bearer")
.accessToken(accessToken)
.role(Role.ROLE_TEMP_USER)
.userId(user.getId())
.build();
}
}else{
String randomCode = RandomStringUtils.randomAlphanumeric(6);
String randomPassword = RandomStringUtils.randomAlphanumeric(10);
String email = sendCode.getEmail();
String code = mailService.sendMail(email, "Moment 인증코드", "인증코드 : " + randomCode);
if (Objects.equals(code, "success")) {
User user = User.builder()
.email(email)
.password(passwordEncoder.encode(randomPassword))
.role(Role.ROLE_TEMP_USER)
.verificationCode(randomCode)
.build();
userService.save(user);
String accessToken = jwtTokenUtils.generateAccessToken(provider, iss, user.getId(), Role.ROLE_TEMP_USER);
return TokenResponseDTO.GetTempToken.builder()
.grantType("Bearer")
.accessToken(accessToken)
.role(Role.ROLE_TEMP_USER)
.userId(user.getId())
.build();
}
}
String randomCode = RandomStringUtils.randomAlphanumeric(6);
String randomPassword = RandomStringUtils.randomAlphanumeric(10);
String email = sendCode.getEmail();
String code = mailService.sendMail(email, "Moment 인증코드", "인증코드 : " + randomCode);
if (Objects.equals(code, "success")) {
User user = User.builder()
.email(email)
.password(passwordEncoder.encode(randomPassword))
.role(Role.ROLE_TEMP_USER)
.verificationCode(randomCode)
.build();
userService.save(user);
String accessToken = jwtTokenUtils.generateAccessToken(provider, iss, user.getId(), Role.ROLE_TEMP_USER);
return TokenResponseDTO.GetTempToken.builder()
.grantType("Bearer")
.accessToken(accessToken)
.role(Role.ROLE_TEMP_USER)
.userId(user.getId())
.build();

}
else throw new IllegalArgumentException("인증코드 전송 실패");
}
else {
User user = userRepository.findByEmail(sendCode.getEmail()).orElseThrow(() -> new AlreadyRegisteredEmailException("미 가입된 이메일"));
Expand All @@ -83,6 +99,7 @@ public TokenResponseDTO.GetTempToken sendCode(AuthRequest.SendCode sendCode) {
}
else throw new IllegalArgumentException("인증코드 전송 실패");
}
return null;
}


Expand Down
Loading

0 comments on commit 0d310ca

Please sign in to comment.