관리자 관리수정, 에러코드 공통 추가
This commit is contained in:
@@ -7,6 +7,7 @@ import com.kamco.cd.kamcoback.members.dto.SignInRequest;
|
||||
import com.kamco.cd.kamcoback.members.service.AuthService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.ExampleObject;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
@@ -14,7 +15,6 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.nio.file.AccessDeniedException;
|
||||
import java.time.Duration;
|
||||
import java.util.UUID;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -55,12 +55,43 @@ public class AuthController {
|
||||
content = @Content(schema = @Schema(implementation = TokenResponse.class))),
|
||||
@ApiResponse(
|
||||
responseCode = "401",
|
||||
description = "ID 또는 비밀번호 불일치",
|
||||
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
|
||||
@ApiResponse(
|
||||
responseCode = "400",
|
||||
description = "미사용 상태",
|
||||
content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
|
||||
description = "로그인 실패 (아이디/비밀번호 오류, 계정잠금 등)",
|
||||
content =
|
||||
@Content(
|
||||
schema = @Schema(implementation = ErrorResponse.class),
|
||||
examples = {
|
||||
@ExampleObject(
|
||||
name = "아이디 입력 오류",
|
||||
description = "존재하지 않는 아이디",
|
||||
value = """
|
||||
{
|
||||
"code": "LOGIN_ID_NOT_FOUND",
|
||||
"message": "아이디를 잘못 입력하셨습니다.",
|
||||
"detail": null
|
||||
}
|
||||
"""),
|
||||
@ExampleObject(
|
||||
name = "비밀번호 입력 오류 (4회 이하)",
|
||||
description = "아이디는 정상, 비밀번호를 여러 번 틀린 경우",
|
||||
value = """
|
||||
{
|
||||
"code": "LOGIN_PASSWORD_MISMATCH",
|
||||
"message": "비밀번호를 잘못 입력하셨습니다.",
|
||||
"detail": "비밀번호 입력 오류 3회, 2회 남았습니다."
|
||||
}
|
||||
"""),
|
||||
@ExampleObject(
|
||||
name = "비밀번호 오류 횟수 초과",
|
||||
description = "비밀번호 5회 이상 오류로 계정 잠김",
|
||||
value = """
|
||||
{
|
||||
"code": "LOGIN_PASSWORD_EXCEEDED",
|
||||
"message": "비밀번호 오류 횟수를 초과하여 이용하실 수 없습니다.",
|
||||
"detail": "로그인 오류에 대해 관리자에게 문의하시기 바랍니다."
|
||||
}
|
||||
""")
|
||||
}
|
||||
))
|
||||
})
|
||||
public ApiResponseDto<TokenResponse> signin(
|
||||
@io.swagger.v3.oas.annotations.parameters.RequestBody(
|
||||
@@ -75,15 +106,14 @@ public class AuthController {
|
||||
new UsernamePasswordAuthenticationToken(request.getUsername(), request.getPassword()));
|
||||
|
||||
String status = authService.getUserStatus(request);
|
||||
if ("INACTIVE".equals(status)) {
|
||||
|
||||
// INACTIVE 비활성 상태(새로운 패스워드 입력 해야함), ARCHIVED 탈퇴
|
||||
if (!"ACTIVE".equals(status)) {
|
||||
return ApiResponseDto.ok(new TokenResponse(status, null, null));
|
||||
}
|
||||
|
||||
String username = authentication.getName(); // UserDetailsService 에서 사용한 username
|
||||
|
||||
// 로그인 시간 저장
|
||||
authService.saveLogin(UUID.fromString(username));
|
||||
|
||||
String accessToken = jwtTokenProvider.createAccessToken(username);
|
||||
String refreshToken = jwtTokenProvider.createRefreshToken(username);
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ public class MembersApiController {
|
||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||
})
|
||||
@PatchMapping("/{memberId}/password")
|
||||
public ApiResponseDto<Long> resetPassword(@PathVariable Long memberId, @RequestBody @Valid MembersDto.InitReq initReq) {
|
||||
public ApiResponseDto<String> resetPassword(@PathVariable String memberId, @RequestBody @Valid MembersDto.InitReq initReq) {
|
||||
membersService.resetPassword(memberId, initReq);
|
||||
return ApiResponseDto.createOK(memberId);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.kamco.cd.kamcoback.members.dto;
|
||||
|
||||
import com.kamco.cd.kamcoback.common.enums.RoleType;
|
||||
import com.kamco.cd.kamcoback.common.enums.StatusType;
|
||||
import com.kamco.cd.kamcoback.common.utils.interfaces.JsonFormatDttm;
|
||||
import com.kamco.cd.kamcoback.config.enums.EnumType;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
@@ -22,11 +25,13 @@ public class MembersDto {
|
||||
private Long id;
|
||||
private UUID uuid;
|
||||
private String userRole;
|
||||
private String userRoleName;
|
||||
private String name;
|
||||
private String userId;
|
||||
private String employeeNo;
|
||||
private String tempPassword;
|
||||
private String status;
|
||||
private String statusName;
|
||||
@JsonFormatDttm
|
||||
private ZonedDateTime createdDttm;
|
||||
@JsonFormatDttm
|
||||
@@ -40,11 +45,13 @@ public class MembersDto {
|
||||
Long id,
|
||||
UUID uuid,
|
||||
String userRole,
|
||||
String userRoleName,
|
||||
String name,
|
||||
String userId,
|
||||
String employeeNo,
|
||||
String tempPassword,
|
||||
String status,
|
||||
String statusName,
|
||||
ZonedDateTime createdDttm,
|
||||
ZonedDateTime updatedDttm,
|
||||
ZonedDateTime firstLoginDttm,
|
||||
@@ -53,16 +60,29 @@ public class MembersDto {
|
||||
this.id = id;
|
||||
this.uuid = uuid;
|
||||
this.userRole = userRole;
|
||||
this.userRoleName = getUserRoleName(userRole);
|
||||
this.name = name;
|
||||
this.userId = userId;
|
||||
this.employeeNo = employeeNo;
|
||||
this.tempPassword = tempPassword;
|
||||
this.status = status;
|
||||
this.statusName = getStatusName(status);
|
||||
this.createdDttm = createdDttm;
|
||||
this.updatedDttm = updatedDttm;
|
||||
this.firstLoginDttm = firstLoginDttm;
|
||||
this.lastLoginDttm = lastLoginDttm;
|
||||
}
|
||||
|
||||
private String getUserRoleName(String roleId) {
|
||||
RoleType type = EnumType.fromId(RoleType.class, roleId);
|
||||
return type.getText();
|
||||
}
|
||||
|
||||
private String getStatusName(String status) {
|
||||
StatusType type = EnumType.fromId(StatusType.class, status);
|
||||
return type.getText();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Getter
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.kamco.cd.kamcoback.members.service;
|
||||
|
||||
import com.kamco.cd.kamcoback.members.dto.SignInRequest;
|
||||
import com.kamco.cd.kamcoback.postgres.core.MembersCoreService;
|
||||
import java.util.UUID;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -14,26 +13,6 @@ public class AuthService {
|
||||
|
||||
private final MembersCoreService membersCoreService;
|
||||
|
||||
/**
|
||||
* 로그인 일시 저장
|
||||
*
|
||||
* @param uuid
|
||||
*/
|
||||
@Transactional
|
||||
public void saveLogin(UUID uuid) {
|
||||
membersCoreService.saveLogin(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 로그인 실패 저장
|
||||
*
|
||||
* @param uuid
|
||||
*/
|
||||
@Transactional
|
||||
public void loginFail(UUID uuid) {
|
||||
membersCoreService.loginFail(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 사용자 상태 조회
|
||||
*
|
||||
|
||||
@@ -35,7 +35,7 @@ public class MembersService {
|
||||
* @param initReq
|
||||
*/
|
||||
@Transactional
|
||||
public void resetPassword(Long id, MembersDto.InitReq initReq) {
|
||||
public void resetPassword(String id, MembersDto.InitReq initReq) {
|
||||
if (!isValidPassword(initReq.getPassword())) {
|
||||
throw new CustomApiException("WRONG_PASSWORD", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
@@ -49,7 +49,8 @@ public class MembersService {
|
||||
* @return
|
||||
*/
|
||||
private boolean isValidPassword(String password) {
|
||||
String regex = "^(?=.*[A-Z])(?=.*[a-z])(?=.*\\d)(?=.*[!@#$]).{8,20}$";
|
||||
return Pattern.matches(regex, password);
|
||||
String passwordPattern =
|
||||
"^(?=.*[A-Za-z])(?=.*\\d)(?=.*[!@#$%^&*()_+\\-\\[\\]{};':\"\\\\|,.<>/?]).{8,20}$";
|
||||
return Pattern.matches(passwordPattern, password);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user