-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- /api/userLogin 추가 - 로그인 대상 정보 확인 및 토큰 발행 - 로그인 유지여부 상태 업데이트 처리
- Loading branch information
1 parent
7b8a7a4
commit a2e4aad
Showing
13 changed files
with
287 additions
and
41 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package kr.co.hconnect.domain; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
|
||
import javax.validation.constraints.NotNull; | ||
import javax.validation.constraints.Pattern; | ||
import javax.validation.constraints.Size; | ||
import java.io.Serializable; | ||
|
||
/** | ||
* 사용자 로그인 정보 | ||
*/ | ||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@ToString | ||
public class UserLoginInfo implements Serializable { | ||
|
||
private static final long serialVersionUID = -1773620410222057699L; | ||
|
||
/** | ||
* 아이디 | ||
*/ | ||
@NotNull(message = "{validation.null.loginId}") | ||
private String loginId; | ||
|
||
/** | ||
* 비밀번호 | ||
*/ | ||
@NotNull(message = "{validation.null.password}") | ||
@Size(max = 20, message = "{validation.size.password}") | ||
private String password; | ||
|
||
/** | ||
* 로그인 유지 여부 | ||
*/ | ||
@Pattern(regexp = "^[YN]$") | ||
private String rememberYn; | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/kr/co/hconnect/domain/UserLoginResponse.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,23 @@ | ||
package kr.co.hconnect.domain; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
|
||
/** | ||
* 로그인 응답 정보 | ||
*/ | ||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@ToString | ||
public class UserLoginResponse extends BaseResponse { | ||
|
||
private static final long serialVersionUID = -2461380484928982120L; | ||
|
||
/** | ||
* AccessToken | ||
*/ | ||
private String token; | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/kr/co/hconnect/exception/NotFoundUserInfoException.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,23 @@ | ||
package kr.co.hconnect.exception; | ||
|
||
/** | ||
* 사용자 정보 미존재 Exception | ||
*/ | ||
public class NotFoundUserInfoException extends RuntimeException { | ||
|
||
private static final long serialVersionUID = 2009383189724700722L; | ||
|
||
/** | ||
* 오류 내역 | ||
*/ | ||
private final String errorMessage; | ||
|
||
public NotFoundUserInfoException(String errorMessage) { | ||
this.errorMessage = errorMessage; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return errorMessage; | ||
} | ||
} |
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
79 changes: 79 additions & 0 deletions
79
src/main/java/kr/co/hconnect/rest/UserLoginRestController.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,79 @@ | ||
package kr.co.hconnect.rest; | ||
|
||
import kr.co.hconnect.common.ApiResponseCode; | ||
import kr.co.hconnect.domain.UserLoginInfo; | ||
import kr.co.hconnect.domain.UserLoginResponse; | ||
import kr.co.hconnect.exception.InvalidRequestArgumentException; | ||
import kr.co.hconnect.exception.NotFoundUserInfoException; | ||
import kr.co.hconnect.exception.NotMatchPatientPasswordException; | ||
import kr.co.hconnect.jwt.TokenProvider; | ||
import kr.co.hconnect.service.UserService; | ||
import kr.co.hconnect.vo.UserVO; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.validation.BindingResult; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import javax.validation.Valid; | ||
|
||
@CrossOrigin | ||
@RestController | ||
@RequestMapping("/api") | ||
public class UserLoginRestController { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(UserLoginRestController.class); | ||
|
||
private final TokenProvider tokenProvider; | ||
|
||
/** | ||
* 사용자 서비스 | ||
*/ | ||
private final UserService userService; | ||
|
||
/** | ||
* 생성자 | ||
* @param tokenProvider Token 관리 | ||
* @param userService 사용자 서비스 | ||
*/ | ||
public UserLoginRestController(TokenProvider tokenProvider, UserService userService) { | ||
this.tokenProvider = tokenProvider; | ||
this.userService = userService; | ||
} | ||
|
||
/** | ||
* 로그인 정보 확인 | ||
*/ | ||
@RequestMapping(value="/userLogin", method = RequestMethod.POST) | ||
public UserLoginResponse checkLogin(@Valid @RequestBody UserLoginInfo userLoginInfo, BindingResult bindingResult) { | ||
if (bindingResult.hasErrors()) { | ||
throw new InvalidRequestArgumentException(bindingResult); | ||
} | ||
|
||
UserLoginResponse userLoginResponse = new UserLoginResponse(); | ||
|
||
try { | ||
// 로그인 정보 조회 | ||
UserVO userVO = userService.selectLoginInfo(userLoginInfo); | ||
|
||
// 사용자 로그인 정보 업데이트 | ||
userVO.setRememberYn(userLoginInfo.getRememberYn()); | ||
userService.updateUserLoginInfo(userVO); | ||
|
||
// Token 발행 | ||
String token = tokenProvider.createUserToken(userVO); | ||
|
||
userLoginResponse.setCode(ApiResponseCode.SUCCESS.getCode()); | ||
userLoginResponse.setMessage("로그인 성공"); | ||
userLoginResponse.setToken(token); | ||
} catch (NotFoundUserInfoException e) { | ||
userLoginResponse.setCode(ApiResponseCode.NOT_FOUND_USER_INFO.getCode()); | ||
userLoginResponse.setMessage(e.getMessage()); | ||
} catch (NotMatchPatientPasswordException e) { | ||
userLoginResponse.setCode(ApiResponseCode.NOT_MATCH_PATIENT_PASSWORD.getCode()); | ||
userLoginResponse.setMessage(e.getMessage()); | ||
} | ||
|
||
return userLoginResponse; | ||
} | ||
|
||
} |
Oops, something went wrong.