-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from JNU-econovation/feature/BE-40
[BE-40] IDP 로그인, 회원가입
- Loading branch information
Showing
33 changed files
with
343 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
server/.gradle/7.6.1/executionHistory/executionHistory.lock
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 0 additions & 38 deletions
38
server/Recruit-Api/src/main/java/com/econovation/recruit/api/user/UserController.java
This file was deleted.
Oops, something went wrong.
66 changes: 66 additions & 0 deletions
66
...Recruit-Api/src/main/java/com/econovation/recruit/api/user/controller/UserController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.econovation.recruit.api.user.controller; | ||
|
||
import static com.econovation.recruitcommon.consts.RecruitStatic.INTERVIEWER_SUCCESS_SIGNUP_MESSAGE; | ||
|
||
import com.econovation.recruit.api.interviewer.docs.InterviewerExceptionDocs; | ||
import com.econovation.recruit.api.user.usecase.UserLoginUseCase; | ||
import com.econovation.recruit.api.user.usecase.UserRegisterUseCase; | ||
import com.econovation.recruitcommon.annotation.ApiErrorExceptionsExample; | ||
import com.econovation.recruitcommon.annotation.DevelopOnlyApi; | ||
import com.econovation.recruitcommon.dto.TokenResponse; | ||
import com.econovation.recruitcommon.jwt.JwtTokenProvider; | ||
import com.econovation.recruitdomain.domains.dto.LoginRequestDto; | ||
import com.econovation.recruitdomain.domains.dto.SignUpRequestDto; | ||
import com.econovation.recruitdomain.domains.interviewer.domain.Role; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import javax.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1") | ||
@Slf4j | ||
@Tag(name = "[0.0]. 유저 관련 API", description = "유저 API") | ||
public class UserController { | ||
private final JwtTokenProvider jwtTokenProvider; | ||
private final UserRegisterUseCase userRegisterUseCase; | ||
private final UserLoginUseCase userLoginUseCase; | ||
private final Long tempId = 0L; | ||
|
||
@DevelopOnlyApi | ||
@Operation(summary = "임시 토큰을 발급합니다.") | ||
@GetMapping("/token") | ||
public ResponseEntity<TokenResponse> issueToken() { | ||
log.info("tempId: {}", tempId); | ||
String accessToken = jwtTokenProvider.generateAccessToken(tempId, Role.ROLE_TF.getRole()); | ||
String refreshToken = jwtTokenProvider.generateRefreshToken(tempId); | ||
log.info("accessToken: {}", accessToken); | ||
log.info("refreshToken: {}", refreshToken); | ||
TokenResponse tokenResponse = new TokenResponse(accessToken, refreshToken); | ||
return new ResponseEntity<>(tokenResponse, HttpStatus.OK); | ||
} | ||
|
||
@Operation(summary = "로그인합니다.", description = "accessToken, refreshToken을 발급합니다.") | ||
@PostMapping("/login") | ||
public ResponseEntity<TokenResponse> login(LoginRequestDto loginRequestDto) { | ||
TokenResponse tokenResponse = userLoginUseCase.execute(loginRequestDto); | ||
return new ResponseEntity<>(tokenResponse, HttpStatus.OK); | ||
} | ||
|
||
@Operation(summary = "회원가입합니다.", description = "회원가입합니다.") | ||
@ApiErrorExceptionsExample(InterviewerExceptionDocs.class) | ||
@PostMapping("/signup") | ||
public ResponseEntity<String> signUp(@Valid @RequestBody SignUpRequestDto signUpRequestDto) { | ||
userRegisterUseCase.signUp(signUpRequestDto); | ||
return new ResponseEntity<>(INTERVIEWER_SUCCESS_SIGNUP_MESSAGE, HttpStatus.OK); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...r/Recruit-Api/src/main/java/com/econovation/recruit/api/user/docs/LoginExceptionDocs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.econovation.recruit.api.user.docs; | ||
|
||
import com.econovation.recruitcommon.annotation.ExceptionDoc; | ||
import com.econovation.recruitcommon.annotation.ExplainError; | ||
import com.econovation.recruitcommon.exception.RecruitCodeException; | ||
import com.econovation.recruitcommon.interfaces.SwaggerExampleExceptions; | ||
import com.econovation.recruitdomain.domains.interviewer.exception.InterviewerNotMatchException; | ||
import com.econovation.recruitdomain.domains.interviewer.exception.InvalidPasswordException; | ||
|
||
@ExceptionDoc | ||
public class LoginExceptionDocs implements SwaggerExampleExceptions { | ||
@ExplainError("유효하지 않은 비밀번호를 입력한 경우") | ||
public RecruitCodeException 비밀번호_부적절 = InvalidPasswordException.EXCEPTION; | ||
|
||
@ExplainError("등록되지 않은 이메일과 비밀번호로 로그인을 시도한 경우") | ||
public RecruitCodeException 이메일_비밀번호_불일치 = InterviewerNotMatchException.EXCEPTION; | ||
} |
13 changes: 13 additions & 0 deletions
13
.../Recruit-Api/src/main/java/com/econovation/recruit/api/user/docs/SignUpExceptionDocs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.econovation.recruit.api.user.docs; | ||
|
||
import com.econovation.recruitcommon.annotation.ExceptionDoc; | ||
import com.econovation.recruitcommon.annotation.ExplainError; | ||
import com.econovation.recruitcommon.exception.RecruitCodeException; | ||
import com.econovation.recruitcommon.interfaces.SwaggerExampleExceptions; | ||
import com.econovation.recruitdomain.domains.interviewer.exception.InvalidPasswordException; | ||
|
||
@ExceptionDoc | ||
public class SignUpExceptionDocs implements SwaggerExampleExceptions { | ||
@ExplainError("유효하지 않은 비밀번호를 입력한 경우") | ||
public RecruitCodeException 비밀번호_부적절 = InvalidPasswordException.EXCEPTION; | ||
} |
55 changes: 55 additions & 0 deletions
55
server/Recruit-Api/src/main/java/com/econovation/recruit/api/user/service/UserService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.econovation.recruit.api.user.service; | ||
|
||
import com.econovation.recruit.api.user.usecase.UserLoginUseCase; | ||
import com.econovation.recruit.api.user.usecase.UserRegisterUseCase; | ||
import com.econovation.recruitcommon.dto.TokenResponse; | ||
import com.econovation.recruitcommon.jwt.JwtTokenProvider; | ||
import com.econovation.recruitdomain.domains.dto.LoginRequestDto; | ||
import com.econovation.recruitdomain.domains.dto.SignUpRequestDto; | ||
import com.econovation.recruitdomain.domains.interviewer.domain.Interviewer; | ||
import com.econovation.recruitdomain.domains.interviewer.exception.InterviewerNotMatchException; | ||
import com.econovation.recruitdomain.out.InterviewerLoadPort; | ||
import com.econovation.recruitdomain.out.InterviewerRecordPort; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class UserService implements UserRegisterUseCase, UserLoginUseCase { | ||
private final InterviewerRecordPort interviewerRecordPort; | ||
private final InterviewerLoadPort interviewerLoadPort; | ||
private final JwtTokenProvider jwtTokenProvider; | ||
private final PasswordEncoder passwordEncoder; | ||
|
||
@Override | ||
@Transactional | ||
public TokenResponse execute(LoginRequestDto loginRequestDto) { | ||
Interviewer account = | ||
interviewerLoadPort.loadInterviewerByEmail(loginRequestDto.getEmail()); | ||
checkPassword(loginRequestDto.getPassword(), account.getPassword()); | ||
return jwtTokenProvider.createToken(account.getId(), account.getRole().name()); | ||
} | ||
|
||
private void checkPassword(String password, String encodePassword) { | ||
boolean isMatch = passwordEncoder.matches(password, encodePassword); | ||
if (!isMatch) throw InterviewerNotMatchException.EXCEPTION; | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public void signUp(SignUpRequestDto signUpRequestDto) { | ||
if (interviewerLoadPort.loadInterviewerByEmail(signUpRequestDto.getEmail()) != null) | ||
throw InterviewerNotMatchException.EXCEPTION; | ||
String encededPassword = passwordEncoder.encode(signUpRequestDto.getPassword()); | ||
Interviewer interviewer = | ||
Interviewer.builder() | ||
.year(signUpRequestDto.getYear()) | ||
.name(signUpRequestDto.getName()) | ||
.email(signUpRequestDto.getEmail()) | ||
.password(encededPassword) | ||
.build(); | ||
interviewerRecordPort.save(interviewer); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
.../Recruit-Api/src/main/java/com/econovation/recruit/api/user/usecase/UserLoginUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.econovation.recruit.api.user.usecase; | ||
|
||
import com.econovation.recruitcommon.annotation.UseCase; | ||
import com.econovation.recruitcommon.dto.TokenResponse; | ||
import com.econovation.recruitdomain.domains.dto.LoginRequestDto; | ||
|
||
@UseCase | ||
public interface UserLoginUseCase { | ||
TokenResponse execute(LoginRequestDto loginRequestDto); | ||
} |
10 changes: 10 additions & 0 deletions
10
...cruit-Api/src/main/java/com/econovation/recruit/api/user/usecase/UserRegisterUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.econovation.recruit.api.user.usecase; | ||
|
||
import com.econovation.recruitcommon.annotation.UseCase; | ||
import com.econovation.recruitdomain.domains.dto.SignUpRequestDto; | ||
|
||
@UseCase | ||
public interface UserRegisterUseCase { | ||
|
||
void signUp(SignUpRequestDto signUpRequestDto); | ||
} |
61 changes: 61 additions & 0 deletions
61
...r/Recruit-Api/src/main/java/com/econovation/recruit/utils/aop/PasswordValidateAspect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.econovation.recruit.utils.aop; | ||
|
||
import com.econovation.recruitcommon.annotation.PasswordValidate; | ||
import com.econovation.recruitdomain.domains.interviewer.exception.InvalidPasswordException; | ||
import java.lang.reflect.Field; | ||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.Around; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Aspect | ||
@Component | ||
public class PasswordValidateAspect { | ||
|
||
@Around("@annotation(com.econovation.recruitcommon.annotation.PasswordValidate)") | ||
public Object validatePasswordField(ProceedingJoinPoint joinPoint) throws Throwable { | ||
Object target = joinPoint.getTarget(); | ||
Class<?> targetClass = target.getClass(); | ||
|
||
Field[] fields = targetClass.getDeclaredFields(); | ||
for (Field field : fields) { | ||
if (field.isAnnotationPresent(PasswordValidate.class)) { | ||
field.setAccessible(true); | ||
Object fieldValue = field.get(target); | ||
if (fieldValue instanceof String) { | ||
String password = (String) fieldValue; | ||
if (!isValidPassword(password)) { | ||
throw InvalidPasswordException.EXCEPTION; | ||
} | ||
} | ||
} | ||
} | ||
return joinPoint.proceed(); | ||
} | ||
|
||
private boolean isValidPassword(String password) { | ||
if (password == null || password.length() < 10) { | ||
return false; // 비밀번호 길이가 10글자 미만인 경우 검증 실패 | ||
} | ||
|
||
boolean hasDigit = false; | ||
boolean hasSpecialChar = false; | ||
|
||
for (char ch : password.toCharArray()) { | ||
if (Character.isDigit(ch)) { | ||
hasDigit = true; | ||
} else if (isSpecialCharacter(ch)) { | ||
hasSpecialChar = true; | ||
} | ||
} | ||
|
||
return hasDigit && hasSpecialChar; | ||
} | ||
|
||
private boolean isSpecialCharacter(char ch) { | ||
// 특수 문자 여부를 확인하는 로직을 구현 | ||
// 예를 들어, 일부 특수 문자를 확인할 수 있습니다. | ||
return ch == '@' || ch == '#' || ch == '!' || ch == '$' || ch == '%' || ch == '^' | ||
|| ch == '&' || ch == '*'; | ||
} | ||
} |
Oops, something went wrong.