관리자 관리 수정
This commit is contained in:
@@ -12,7 +12,6 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.UUID;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
@@ -87,24 +86,4 @@ public class AdminApiController {
|
||||
adminService.updateMembers(uuid, updateReq);
|
||||
return ApiResponseDto.createOK(UUID.randomUUID());
|
||||
}
|
||||
|
||||
@Operation(summary = "관리자 계정 미사용 처리", description = "관리자 계정 미사용 처리")
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
responseCode = "201",
|
||||
description = "관리자 계정 미사용 처리",
|
||||
content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = UUID.class))),
|
||||
@ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content),
|
||||
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
|
||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||
})
|
||||
@DeleteMapping("/delete/{uuid}")
|
||||
public ApiResponseDto<UUID> deleteAccount(@PathVariable UUID uuid) {
|
||||
adminService.deleteAccount(uuid);
|
||||
return ApiResponseDto.createOK(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ public class AuthController {
|
||||
MembersDto.Member member = new MembersDto.Member();
|
||||
|
||||
// 비활성 상태면 임시패스워드를 비교함
|
||||
if (StatusType.INACTIVE.getId().equals(status)) {
|
||||
if (StatusType.PENDING.getId().equals(status)) {
|
||||
if (!authService.isTempPasswordValid(request)) {
|
||||
throw new CustomApiException(AuthErrorCode.LOGIN_PASSWORD_MISMATCH);
|
||||
}
|
||||
@@ -124,8 +124,9 @@ public class AuthController {
|
||||
request.getUsername(), request.getPassword()));
|
||||
}
|
||||
|
||||
// INACTIVE 비활성 상태(새로운 패스워드 입력 해야함), DELETED 탈퇴
|
||||
if (!StatusType.ACTIVE.getId().equals(status)) {
|
||||
// PENDING 비활성 상태(새로운 패스워드 입력 해야함)
|
||||
if (StatusType.PENDING.getId().equals(status)) {
|
||||
member.setEmployeeNo(request.getUsername());
|
||||
return ApiResponseDto.ok(new TokenResponse(status, null, null, member));
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ import lombok.RequiredArgsConstructor;
|
||||
import org.springdoc.core.annotations.ParameterObject;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PatchMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
@@ -70,10 +69,6 @@ public class MembersApiController {
|
||||
@PatchMapping("/{memberId}/password")
|
||||
public ApiResponseDto<String> resetPassword(
|
||||
@PathVariable String memberId, @RequestBody @Valid MembersDto.InitReq initReq) {
|
||||
|
||||
authenticationManager.authenticate(
|
||||
new UsernamePasswordAuthenticationToken(memberId, initReq.getTempPassword()));
|
||||
|
||||
membersService.resetPassword(memberId, initReq);
|
||||
return ApiResponseDto.createOK(memberId);
|
||||
}
|
||||
|
||||
@@ -108,32 +108,26 @@ public class MembersDto {
|
||||
|
||||
@Schema(description = "관리자 유형", example = "ADMIN")
|
||||
@NotBlank
|
||||
@EnumValid(enumClass = RoleType.class, message = "userRole은 ADMIN, LABELER, REVIEWER만 가능합니다.")
|
||||
@EnumValid(enumClass = RoleType.class, message = "userRole은 ADMIN, LABELER, REVIEWER 만 가능합니다.")
|
||||
private String userRole;
|
||||
|
||||
@Schema(description = "사번", example = "K20251212001")
|
||||
@Size(max = 50)
|
||||
private String employeeNo;
|
||||
|
||||
@Schema(description = "이름", example = "홍길동")
|
||||
@NotBlank
|
||||
@Size(min = 2, max = 100)
|
||||
private String name;
|
||||
|
||||
@Schema(description = "ID", example = "gildong")
|
||||
@NotBlank
|
||||
@Size(min = 2, max = 50)
|
||||
private String userId;
|
||||
|
||||
@Schema(description = "임시 비밀번호", example = "q!w@e#r4")
|
||||
private String tempPassword;
|
||||
|
||||
@Schema(description = "사번", example = "123456")
|
||||
private String employeeNo;
|
||||
|
||||
public AddReq(
|
||||
String userRole, String name, String userId, String tempPassword, String employeeNo) {
|
||||
public AddReq(String userRole, String employeeNo, String name, String tempPassword) {
|
||||
this.userRole = userRole;
|
||||
this.name = name;
|
||||
this.userId = userId;
|
||||
this.tempPassword = tempPassword;
|
||||
this.employeeNo = employeeNo;
|
||||
this.name = name;
|
||||
this.tempPassword = tempPassword;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,10 +135,6 @@ public class MembersDto {
|
||||
@Setter
|
||||
public static class UpdateReq {
|
||||
|
||||
@Schema(description = "사번, 패스워드 변경시 필수 값", example = "11111")
|
||||
@Size(max = 50)
|
||||
private String employeeNo;
|
||||
|
||||
@Schema(description = "이름", example = "홍길동")
|
||||
@Size(min = 2, max = 100)
|
||||
private String name;
|
||||
@@ -157,8 +147,7 @@ public class MembersDto {
|
||||
@EnumValid(enumClass = StatusType.class, message = "status는 ACTIVE, INACTIVE, DELETED 만 가능합니다.")
|
||||
private String status;
|
||||
|
||||
public UpdateReq(String employeeNo, String name, String tempPassword, String status) {
|
||||
this.employeeNo = employeeNo;
|
||||
public UpdateReq(String name, String tempPassword, String status) {
|
||||
this.name = name;
|
||||
this.tempPassword = tempPassword;
|
||||
this.status = status;
|
||||
|
||||
@@ -11,6 +11,7 @@ public class MemberException {
|
||||
|
||||
public enum Field {
|
||||
USER_ID,
|
||||
EMPLOYEE_NO,
|
||||
DEFAULT
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package com.kamco.cd.kamcoback.members.service;
|
||||
|
||||
import com.kamco.cd.kamcoback.common.enums.StatusType;
|
||||
import com.kamco.cd.kamcoback.common.exception.CustomApiException;
|
||||
import com.kamco.cd.kamcoback.common.utils.CommonStringUtils;
|
||||
import com.kamco.cd.kamcoback.members.dto.MembersDto;
|
||||
import com.kamco.cd.kamcoback.postgres.core.MembersCoreService;
|
||||
import java.util.UUID;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -22,6 +26,10 @@ public class AdminService {
|
||||
*/
|
||||
@Transactional
|
||||
public Long saveMember(MembersDto.AddReq addReq) {
|
||||
if (!CommonStringUtils.isValidPassword(addReq.getTempPassword())) {
|
||||
throw new CustomApiException("WRONG_PASSWORD", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
return membersCoreService.saveMembers(addReq);
|
||||
}
|
||||
|
||||
@@ -33,16 +41,12 @@ public class AdminService {
|
||||
*/
|
||||
@Transactional
|
||||
public void updateMembers(UUID uuid, MembersDto.UpdateReq updateReq) {
|
||||
membersCoreService.updateMembers(uuid, updateReq);
|
||||
}
|
||||
|
||||
/**
|
||||
* 관리자 계정 미사용 처리
|
||||
*
|
||||
* @param uuid
|
||||
*/
|
||||
@Transactional
|
||||
public void deleteAccount(UUID uuid) {
|
||||
membersCoreService.deleteAccount(uuid);
|
||||
if (StatusType.INACTIVE.getId().equals(updateReq.getStatus())) {
|
||||
// 미사용 처리
|
||||
membersCoreService.deleteMember(uuid);
|
||||
} else {
|
||||
// 수정
|
||||
membersCoreService.updateMembers(uuid, updateReq);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.kamco.cd.kamcoback.members.service;
|
||||
|
||||
import com.kamco.cd.kamcoback.common.exception.CustomApiException;
|
||||
import com.kamco.cd.kamcoback.common.utils.CommonStringUtils;
|
||||
import com.kamco.cd.kamcoback.members.dto.MembersDto;
|
||||
import com.kamco.cd.kamcoback.members.dto.MembersDto.Basic;
|
||||
import com.kamco.cd.kamcoback.postgres.core.MembersCoreService;
|
||||
import java.util.regex.Pattern;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -37,21 +37,9 @@ public class MembersService {
|
||||
@Transactional
|
||||
public void resetPassword(String id, MembersDto.InitReq initReq) {
|
||||
|
||||
if (!isValidPassword(initReq.getPassword())) {
|
||||
if (!CommonStringUtils.isValidPassword(initReq.getPassword())) {
|
||||
throw new CustomApiException("WRONG_PASSWORD", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
membersCoreService.resetPassword(id, initReq);
|
||||
}
|
||||
|
||||
/**
|
||||
* 영문, 숫자, 특수문자를 모두 포함하여 8~20자 이내의 비밀번호
|
||||
*
|
||||
* @param password
|
||||
* @return
|
||||
*/
|
||||
private boolean isValidPassword(String password) {
|
||||
String passwordPattern =
|
||||
"^(?=.*[A-Za-z])(?=.*\\d)(?=.*[!@#$%^&*()_+\\-\\[\\]{};':\"\\\\|,.<>/?]).{8,20}$";
|
||||
return Pattern.matches(passwordPattern, password);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user