관리자 목록 수정
This commit is contained in:
@@ -58,7 +58,7 @@ public class RoleUpdateAspect {
|
||||
|
||||
if (beforeAdmin.isPresent()) {
|
||||
List<String> beforeRoles =
|
||||
beforeAdmin.get().getRoles().stream().map(CoreRole::getId).toList();
|
||||
beforeAdmin.stream().map(r -> r.getRole().getId()).toList();
|
||||
if (beforeRoles.size() != currentRoles.size()
|
||||
|| currentRoles.stream().anyMatch(item -> !beforeRoles.contains(item))) {
|
||||
createLog = true;
|
||||
|
||||
@@ -44,14 +44,14 @@ public class AdminDetailsService implements UserDetailsService {
|
||||
adminUser.getSeq(),
|
||||
adminUser.getId(),
|
||||
adminUser.getPassword(),
|
||||
adminUser.getRoles().stream().map(CoreRole::getId).findFirst().orElse(null),
|
||||
adminUser.getRole().getId(),
|
||||
adminUser.getRegionMainCode(),
|
||||
adminUser.getLastLoginIp(),
|
||||
!accountDisabled,
|
||||
true,
|
||||
isCredentialsNonExpired(adminUser.getPasswordUpdatedAt()),
|
||||
!accountLocked,
|
||||
getAuthorities(adminUser.getRoles()),
|
||||
getAuthorities(Stream.of(adminUser.getRole()).toList()),
|
||||
passwordValidPeriodDays - getDaysPassedFrom(adminUser.getPasswordUpdatedAt()));
|
||||
}
|
||||
|
||||
|
||||
@@ -41,9 +41,9 @@ public class AdminCreatePostController {
|
||||
savePortIn.apiConnect(bindingVO.getSeq(),
|
||||
bindingVO.getId(),
|
||||
bindingVO.getPassword(),
|
||||
bindingVO.getName(),
|
||||
"010-"+bindingVO.getPhone1()+"-"+bindingVO.getPhone2(),
|
||||
bindingVO.getRegionMainCode(),
|
||||
"ROLE_RESEARCHER".equals(bindingVO.getRoleId())?bindingVO.getName():null,
|
||||
"ROLE_RESEARCHER".equals(bindingVO.getRoleId())?"010-"+bindingVO.getPhone1()+"-"+bindingVO.getPhone2():null,
|
||||
!"ROLE_ADMIN".equals(bindingVO.getRoleId())?bindingVO.getRegionMainCode():null,
|
||||
bindingVO.getAccountDisabled(),
|
||||
bindingVO.getRoleId()));
|
||||
}
|
||||
|
||||
@@ -46,19 +46,16 @@ class AdminUpdateGetController {
|
||||
|
||||
AdminUpdateBindingVO bindingVO =
|
||||
new AdminUpdateBindingVO(
|
||||
output.getCreatedBy(),
|
||||
output.getCreatedAt(),
|
||||
output.getUpdatedBy(),
|
||||
output.getUpdatedAt(),
|
||||
output.getSeq(),
|
||||
output.getId(),
|
||||
null,
|
||||
output.getName(),
|
||||
output.getPhone(),
|
||||
output.getPhone().split("-")[1],
|
||||
output.getPhone().split("-")[2],
|
||||
output.getRegionMainCode(),
|
||||
output.getPasswordUpdatedAt(),
|
||||
output.getAccountDisabled(),
|
||||
output.getRoles().stream().map(CoreRole::getId).collect(Collectors.toList()));
|
||||
output.getRole().getId());
|
||||
|
||||
model.addAttribute("bindingVO", bindingVO);
|
||||
model.addAttribute("roles", roleListPortIn.connect(AppType.ADMIN));
|
||||
|
||||
@@ -9,16 +9,20 @@ import app.module.core.usecase.role.list.ports.RoleListPortIn;
|
||||
import app.module.core.usecase.uicode.list.ports.UICodeListPortIn;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Controller
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
class AdminUpdatePostController {
|
||||
|
||||
@@ -28,34 +32,24 @@ class AdminUpdatePostController {
|
||||
private final SaveAdminPortIn saveAdminPortIn;
|
||||
private final MessageUtil messageUtil;
|
||||
|
||||
@PostMapping(path = "/settings/admins/update/{id}")
|
||||
String operate(
|
||||
Model model,
|
||||
RedirectAttributes redirectAttributes,
|
||||
@Valid @ModelAttribute("bindingVO") AdminUpdateBindingVO bindingVO,
|
||||
BindingResult bindingResult) {
|
||||
@PostMapping(path = "/api/settings/admin/update")
|
||||
ResponseEntity<?> operate( @RequestBody AdminUpdateBindingVO bindingVO, BindingResult bindingResult) {
|
||||
|
||||
adminUpdateValidator.validate(bindingVO, bindingResult);
|
||||
if (bindingResult.hasErrors()) {
|
||||
model.addAttribute("roles", roleListPortIn.connect(AppType.ADMIN));
|
||||
model.addAttribute("regionMainCode", uiCodeListPortIn.connect("code.region.main"));
|
||||
return "admin/adminUpdateForm";
|
||||
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY.value())
|
||||
.body(bindingResult.getAllErrors().get(0).getDefaultMessage());
|
||||
}
|
||||
|
||||
saveAdminPortIn.apiConnect(
|
||||
bindingVO.getSeq(),
|
||||
bindingVO.getId(),
|
||||
bindingVO.getUpdatePassword(),
|
||||
bindingVO.getName(),
|
||||
bindingVO.getPhone(),
|
||||
bindingVO.getRegionMainCode(),
|
||||
bindingVO.getAccountDisabled(),
|
||||
bindingVO.getRoleIds().stream().collect(Collectors.joining()));
|
||||
|
||||
redirectAttributes.addFlashAttribute(
|
||||
"operationMessage",
|
||||
messageUtil.getMessage("operation.settings.admin.updated", bindingVO.getId()));
|
||||
|
||||
return "redirect:/settings/admins";
|
||||
return ResponseEntity.status(HttpStatus.OK).body(
|
||||
saveAdminPortIn.apiConnect(
|
||||
bindingVO.getSeq(),
|
||||
bindingVO.getId(),
|
||||
bindingVO.getUpdatePassword(),
|
||||
"ROLE_RESEARCHER".equals(bindingVO.getRoleId())?bindingVO.getName():null,
|
||||
"ROLE_RESEARCHER".equals(bindingVO.getRoleId())?"010-"+bindingVO.getPhone1()+"-"+bindingVO.getPhone2():null,
|
||||
!"ROLE_ADMIN".equals(bindingVO.getRoleId())? bindingVO.getRegionMainCode():null,
|
||||
bindingVO.getAccountDisabled(),
|
||||
bindingVO.getRoleId()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,16 @@
|
||||
package app.module.admin.usecase.admin.saveAdmin.adapters.web.model;
|
||||
|
||||
import app.module.core.config.application.component.AuditOutput;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class AdminUpdateBindingVO implements AuditOutput {
|
||||
|
||||
private final String createdBy;
|
||||
|
||||
private final LocalDateTime createdAt;
|
||||
|
||||
private final String updatedBy;
|
||||
|
||||
private final LocalDateTime updatedAt;
|
||||
@NoArgsConstructor
|
||||
public class AdminUpdateBindingVO{
|
||||
|
||||
private Long seq;
|
||||
private String id;
|
||||
@@ -33,12 +23,13 @@ public class AdminUpdateBindingVO implements AuditOutput {
|
||||
message = "{valid.common.email.wrong}")
|
||||
private String email;*/
|
||||
private String name;
|
||||
private String phone;
|
||||
private String phone1;
|
||||
private String phone2;
|
||||
private String regionMainCode;
|
||||
|
||||
private LocalDateTime passwordUpdatedAt;
|
||||
private Boolean accountDisabled;
|
||||
/* private Integer loginFailCnt;
|
||||
private Boolean accountLocked;*/
|
||||
private List<String> roleIds;
|
||||
private String roleId;
|
||||
}
|
||||
|
||||
@@ -4,12 +4,14 @@ import app.module.admin.usecase.admin.saveAdmin.adapters.web.model.AdminUpdateBi
|
||||
import java.util.Optional;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.ValidationUtils;
|
||||
import org.springframework.validation.Validator;
|
||||
|
||||
@Component
|
||||
public class AdminUpdateValidator implements Validator {
|
||||
|
||||
private final String PASSWORD_REGEX = "^((?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%_\\-])\\S{6,15})$";
|
||||
// 비밀번호: 5자, 숫자 + 특수문자(!@#$%_-) 1개 이상
|
||||
private final String PASSWORD_REGEX = "^(?=.*[0-9])(?=.*[!@#$%_\\-]).{5}$";
|
||||
|
||||
@Override
|
||||
public boolean supports(Class<?> clazz) {
|
||||
@@ -20,23 +22,38 @@ public class AdminUpdateValidator implements Validator {
|
||||
public void validate(Object target, Errors errors) {
|
||||
AdminUpdateBindingVO vo = (AdminUpdateBindingVO) target;
|
||||
|
||||
Optional.ofNullable(vo.getRoleIds())
|
||||
.filter(ids -> ids.size() < 1)
|
||||
.ifPresent(
|
||||
ids ->
|
||||
errors.rejectValue(
|
||||
"roleIds", "valid.common.required.size.min", new Object[]{1}, ""));
|
||||
if (vo.getRoleId() == null || vo.getRoleId().isEmpty()) {
|
||||
errors.rejectValue("roleId", "error.roleId", "권한을 선택해주세요.");
|
||||
}
|
||||
|
||||
Optional.ofNullable(vo.getUpdatePassword())
|
||||
.filter(s -> !s.trim().isEmpty() && !s.matches(PASSWORD_REGEX))
|
||||
.ifPresent(s -> errors.rejectValue("updatePassword", "valid.common.password.wrong"));
|
||||
.filter(password -> !password.trim().isEmpty() && !password.matches(PASSWORD_REGEX))
|
||||
.ifPresent(password -> errors.rejectValue("updatePassword", "valid.common.password.wrong","비밀번호는 5자, 숫자 + 특수문자(!@#$%_-) 1개 이상입니다."));
|
||||
|
||||
if (vo.getRoleId() != null && "ROLE_RESEARCHER".equals(vo.getRoleId())) {
|
||||
if (vo.getName() == null || vo.getName().isBlank()) {
|
||||
errors.rejectValue("name", "error.name", "이름을 입력해주세요.");
|
||||
}
|
||||
if (vo.getName().length() > 4) {
|
||||
errors.rejectValue("name", "error.name", "이름은 4자리까지 입력가능합니다.");
|
||||
}
|
||||
if (vo.getPhone1() == null || vo.getPhone1().isBlank()) {
|
||||
errors.rejectValue("phone1", "error.phone1", "전화번호 앞자리를 입력해주세요.");
|
||||
} else if (!vo.getPhone1().matches("^\\d{4}$")) {
|
||||
errors.rejectValue("phone1", "error.phone1", "전화번호 앞자리는 4자리 숫자여야 합니다.");
|
||||
}
|
||||
if (vo.getPhone2() == null || vo.getPhone2().isBlank()) {
|
||||
errors.rejectValue("phone2", "error.phone2", "전화번호 뒷자리를 입력해주세요.");
|
||||
} else if (!vo.getPhone2().matches("^\\d{4}$")) {
|
||||
errors.rejectValue("phone2", "error.phone2", "전화번호 뒷자리는 4자리 숫자여야 합니다.");
|
||||
}
|
||||
}
|
||||
// ROLE_ADMIN이 아닌 경우 regionMainCode null체크
|
||||
Optional.ofNullable(vo.getRoleIds())
|
||||
.filter(ids -> ids.stream().noneMatch(role -> role.equals("ROLE_ADMIN")))
|
||||
Optional.ofNullable(vo.getRoleId())
|
||||
.filter(id -> !id.equals("ROLE_ADMIN"))
|
||||
.ifPresent(nonAdmins -> {
|
||||
if (vo.getRegionMainCode() == null || vo.getRegionMainCode().isBlank()) {
|
||||
errors.rejectValue("regionMainCode", "valid.common.required");
|
||||
errors.rejectValue("regionMainCode", "valid.common.required","실사지역을 선택해주세요.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public class HomeController {
|
||||
.ifPresent(
|
||||
loginUser -> {
|
||||
model.addAttribute("loginUser", loginUser);
|
||||
model.addAttribute("loginUserRoles", loginUser.getRoles());
|
||||
model.addAttribute("loginUserRoles", loginUser.getRole());
|
||||
});
|
||||
|
||||
return "home";
|
||||
|
||||
Reference in New Issue
Block a user