diff --git a/src/main/java/com/dbnt/kcgfilemanager/BaseController.java b/src/main/java/com/dbnt/kcgfilemanager/BaseController.java index 2c77996..6f8bb9c 100644 --- a/src/main/java/com/dbnt/kcgfilemanager/BaseController.java +++ b/src/main/java/com/dbnt/kcgfilemanager/BaseController.java @@ -1,23 +1,31 @@ package com.dbnt.kcgfilemanager; import com.dbnt.kcgfilemanager.model.UserInfo; +import com.dbnt.kcgfilemanager.service.CommonCodeService; +import lombok.RequiredArgsConstructor; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.servlet.ModelAndView; +import javax.servlet.http.HttpSession; import java.security.Principal; @RestController +@RequiredArgsConstructor public class BaseController { + private final CommonCodeService commonCodeService; + @GetMapping("/") - public ModelAndView loginCheck(Principal principal) { + public ModelAndView loginCheck(Principal principal, HttpSession session) { ModelAndView mav = null; if(principal == null){ mav = new ModelAndView("redirect:/user/login"); }else{ + session.setAttribute("positionList", commonCodeService.selectCommonCodeValue("POSITION")); + session.setAttribute("departmentList", commonCodeService.selectCommonCodeValue("DEPARTMENT")); if(((UserInfo)((UsernamePasswordAuthenticationToken) principal).getPrincipal()).getUserRole().indexOf("ADMIN")>0){ mav = new ModelAndView("redirect:/admin/main"); }else{ diff --git a/src/main/java/com/dbnt/kcgfilemanager/controller/adminController.java b/src/main/java/com/dbnt/kcgfilemanager/controller/adminController.java index 0239756..9d42fe4 100644 --- a/src/main/java/com/dbnt/kcgfilemanager/controller/adminController.java +++ b/src/main/java/com/dbnt/kcgfilemanager/controller/adminController.java @@ -5,16 +5,10 @@ import com.dbnt.kcgfilemanager.model.UserInfo; import com.dbnt.kcgfilemanager.service.CommonCodeService; import com.dbnt.kcgfilemanager.service.UserInfoService; import lombok.RequiredArgsConstructor; -import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; @RestController @RequiredArgsConstructor @@ -35,8 +29,6 @@ public class adminController { userInfo.setQueryInfo(); ModelAndView mav = new ModelAndView("admin/userMgt"); mav.addObject("userInfoList", userInfoService.selectUserInfoList(userInfo)); - mav.addObject("positionList", commonCodeService.selectCommonCodeValue("POSITION")); - mav.addObject("departmentList", commonCodeService.selectCommonCodeValue("DEPARTMENT")); userInfo.setContentCnt(userInfoService.selectUserInfoListCnt(userInfo)); userInfo.setPaginationInfo(); mav.addObject("searchParams", userInfo); @@ -48,6 +40,17 @@ public class adminController { return userInfoService.insertUserInfo(userInfo); } + @PostMapping("/updateUserInfo") + public String updateUserInfo(UserInfo userInfo){ + return userInfoService.updateUserInfo(userInfo); + } + + @GetMapping("/selectUserInfo") + public ModelAndView selectUserInfo(UserInfo userInfo){ + ModelAndView mav = new ModelAndView("admin/userInfo"); + mav.addObject("userInfo", userInfoService.selectUserInfo(userInfo)); + return mav; + } @GetMapping("/modifyRequest") public ModelAndView modifyRequest() { ModelAndView mav = new ModelAndView("admin/modifyRequest"); diff --git a/src/main/java/com/dbnt/kcgfilemanager/model/BaseModel.java b/src/main/java/com/dbnt/kcgfilemanager/model/BaseModel.java index 3c846cc..a979732 100644 --- a/src/main/java/com/dbnt/kcgfilemanager/model/BaseModel.java +++ b/src/main/java/com/dbnt/kcgfilemanager/model/BaseModel.java @@ -41,7 +41,7 @@ public class BaseModel { int pageIndex = getPageIndex(); int startNum = pageIndex - 2; - if(startNum < 0){ + if(startNum <= 0){ startNum = 1; } setStartNum(startNum); diff --git a/src/main/java/com/dbnt/kcgfilemanager/model/UserInfo.java b/src/main/java/com/dbnt/kcgfilemanager/model/UserInfo.java index bf201f6..6a5d636 100644 --- a/src/main/java/com/dbnt/kcgfilemanager/model/UserInfo.java +++ b/src/main/java/com/dbnt/kcgfilemanager/model/UserInfo.java @@ -3,6 +3,7 @@ package com.dbnt.kcgfilemanager.model; import lombok.*; import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicUpdate; +import org.springframework.data.annotation.CreatedDate; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; @@ -38,7 +39,7 @@ public class UserInfo extends BaseModel implements UserDetails{ private int department; @Column(name = "USER_ROLE") private String userRole; - @Column(name = "CREATE_DATE") + @Column(name = "CREATE_DATE", updatable = false) private LocalDateTime createDate; @Transient diff --git a/src/main/java/com/dbnt/kcgfilemanager/service/UserInfoService.java b/src/main/java/com/dbnt/kcgfilemanager/service/UserInfoService.java index 368169c..a749bd7 100644 --- a/src/main/java/com/dbnt/kcgfilemanager/service/UserInfoService.java +++ b/src/main/java/com/dbnt/kcgfilemanager/service/UserInfoService.java @@ -4,6 +4,7 @@ import com.dbnt.kcgfilemanager.mapper.UserInfoMapper; import com.dbnt.kcgfilemanager.model.UserInfo; import com.dbnt.kcgfilemanager.repository.UserInfoRepository; import lombok.RequiredArgsConstructor; +import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; @@ -12,6 +13,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; +import java.util.Optional; @Service @RequiredArgsConstructor @@ -22,11 +24,26 @@ public class UserInfoService implements UserDetailsService { @Transactional public String insertUserInfo(UserInfo userInfo){ - Pbkdf2PasswordEncoder passwordEncoder = new Pbkdf2PasswordEncoder(); - userInfo.setPassword(passwordEncoder.encode(userInfo.getPassword())); - + userInfo.setPassword(convertPassword(userInfo.getPassword())); return userInfoRepository.save(userInfo).getUserId(); } + @Transactional + public String updateUserInfo(UserInfo userInfo){ + UserInfo targetUserInfo = userInfoRepository.findById(userInfo.getUserSeq()).orElse(null); + if(userInfo.getPassword() != null){ + targetUserInfo.setPassword(convertPassword(userInfo.getPassword())); + } + targetUserInfo.setName(userInfo.getName()); + targetUserInfo.setPosition(userInfo.getPosition()); + targetUserInfo.setDepartment(userInfo.getDepartment()); + targetUserInfo.setUserRole(userInfo.getUserRole()); + return targetUserInfo.getUserId(); + } + + private String convertPassword(String password){ + Pbkdf2PasswordEncoder passwordEncoder = new Pbkdf2PasswordEncoder(); + return passwordEncoder.encode(password); + } @Override public UserDetails loadUserByUsername(String userId) throws UsernameNotFoundException { @@ -40,4 +57,8 @@ public class UserInfoService implements UserDetailsService { public Integer selectUserInfoListCnt(UserInfo userInfo) { return userInfoMapper.selectUserInfoListCnt(userInfo); } + + public UserInfo selectUserInfo(UserInfo userInfo) { + return userInfoRepository.findById(userInfo.getUserSeq()).orElse(null); + } } diff --git a/src/main/resources/mybatisMapper/UserInfoMapper.xml b/src/main/resources/mybatisMapper/UserInfoMapper.xml index 339a066..9da4e08 100644 --- a/src/main/resources/mybatisMapper/UserInfoMapper.xml +++ b/src/main/resources/mybatisMapper/UserInfoMapper.xml @@ -39,6 +39,7 @@ AND A.CREATE_DATE <= #{endDate} + ORDER BY CREATE_DATE DESC LIMIT #{viewCnt} OFFSET #{firstIndex} diff --git a/src/main/resources/static/css/common.css b/src/main/resources/static/css/common.css index 6827921..e720f02 100644 --- a/src/main/resources/static/css/common.css +++ b/src/main/resources/static/css/common.css @@ -1,4 +1,6 @@ - +#loginPage{ + background-image: url("/img/img01.jpg"); +} .form-signin{ width: 100%; max-width: 330px; diff --git a/src/main/resources/static/img/bootstrap-icons-1.7.1/img.png b/src/main/resources/static/img/bootstrap-icons-1.7.1/img.png new file mode 100644 index 0000000..9fdae59 Binary files /dev/null and b/src/main/resources/static/img/bootstrap-icons-1.7.1/img.png differ diff --git a/src/main/resources/static/img/f_logo.png b/src/main/resources/static/img/f_logo.png new file mode 100644 index 0000000..2280228 Binary files /dev/null and b/src/main/resources/static/img/f_logo.png differ diff --git a/src/main/resources/static/img/h_logo.png b/src/main/resources/static/img/h_logo.png new file mode 100644 index 0000000..0351f78 Binary files /dev/null and b/src/main/resources/static/img/h_logo.png differ diff --git a/src/main/resources/static/img/img01.jpg b/src/main/resources/static/img/img01.jpg new file mode 100644 index 0000000..d63beaf Binary files /dev/null and b/src/main/resources/static/img/img01.jpg differ diff --git a/src/main/resources/static/img/img02.jpg b/src/main/resources/static/img/img02.jpg new file mode 100644 index 0000000..9831196 Binary files /dev/null and b/src/main/resources/static/img/img02.jpg differ diff --git a/src/main/resources/static/img/logo.png b/src/main/resources/static/img/logo.png new file mode 100644 index 0000000..9b8ad43 Binary files /dev/null and b/src/main/resources/static/img/logo.png differ diff --git a/src/main/resources/static/img/mVisual_01.jpg b/src/main/resources/static/img/mVisual_01.jpg new file mode 100644 index 0000000..1c6b4ae Binary files /dev/null and b/src/main/resources/static/img/mVisual_01.jpg differ diff --git a/src/main/resources/static/js/admin/codeMgt.js b/src/main/resources/static/js/admin/codeMgt.js index 08116fc..d196349 100644 --- a/src/main/resources/static/js/admin/codeMgt.js +++ b/src/main/resources/static/js/admin/codeMgt.js @@ -104,8 +104,8 @@ function getValues(category){ data: {category: category}, type: 'GET', dataType:"html", - success: function(data){ - $("#valueDiv").empty().append(data) + success: function(html){ + $("#valueDiv").empty().append(html) }, error:function(){ diff --git a/src/main/resources/static/js/admin/userMgt.js b/src/main/resources/static/js/admin/userMgt.js index 62cf372..eab3e3d 100644 --- a/src/main/resources/static/js/admin/userMgt.js +++ b/src/main/resources/static/js/admin/userMgt.js @@ -5,6 +5,24 @@ $(function(){ language: "ko" }); }) +$(document).on('click', '.userInfoTr', function (){ + $(".userInfoCheckBox").prop('checked', false); + const target = $(this).find(".userInfoCheckBox")[0]; + target.checked = true; + const selectedTab = $(".nav-tabs").find(".active")[0].id; + if(selectedTab === "infoTab"){ + getUserInfo(target.value); + }else if(selectedTab === "categoryTab"){ + getCategoryRole(target.value); + } +}) + +$(document).on('click', '#infoTab', function (){ + getUserInfo(getUserSeq()) +}) +$(document).on('click', '#categoryTab', function (){ + getCategoryRole(getUserSeq()) +}) $(document).on('click', '.page-item', function (){ $("#pageIndex").val($(this).attr("data-pageindex")); @@ -14,11 +32,20 @@ $(document).on('click', '.page-item', function (){ $(document).on('change', '#searchConditionSelector', function (){ setSearchCondition(); }) - +$(document).on('change', '#passwordUpdateFlag', function (){ + const passwordDiv = $(".passwordDiv"); + if(this.checked){ + passwordDiv.show(); + passwordDiv.find("input").removeAttr("disabled"); + }else{ + passwordDiv.hide(); + passwordDiv.find("input").attr("disabled", "disabled"); + } +}) $(document).on('click', '#saveBtn', function (){ - if(valueCheck()){ + if(valueCheck("userInfoInsert")){ if(confirm("저장하시겠습니까?")){ - const formData = new FormData($("#userInfoForm")[0]); + const formData = new FormData($("#userInfoInsert")[0]); $.ajax({ type : 'POST', data : formData, @@ -38,30 +65,72 @@ $(document).on('click', '#saveBtn', function (){ } }) -function valueCheck(){ - const password = $("#password").val(); - const passwordConfirm = $("#passwordConfirm").val(); +$(document).on('click', '#updateBtn', function (){ + if(valueCheck("userInfoUpdate")){ + if(confirm("저장하시겠습니까?")){ + const formData = new FormData($("#userInfoUpdate")[0]); + $.ajax({ + type : 'POST', + data : formData, + url : "/admin/updateUserInfo", + processData: false, + contentType: false, + success : function(data) { + alert("저장되었습니다.") + $(".userInfoCheckBox:checked").click(); + }, + error : function(xhr, status) { + + } + }) + } + } +}) + +function valueCheck(form){ + const targetForm = $("#"+form); + const userId = targetForm.find("#userId").val(); + const password = targetForm.find("#password"); + const passwordConfirm = targetForm.find("#passwordConfirm"); + const name = targetForm.find("#name").val() let returnFlag = true; - if(!$("#userId").val()){ + + if(!userId){ alert("아이디를 입력해주세요."); returnFlag = false; + }else{ + const idReg = /^[a-z]+[a-z0-9]{5,19}$/g; + if(!idReg.test(userId)){ + returnFlag = false; + alert("아이디 조건이 맞지 않습니다.") + } } - if(!password){ + if(!password[0].disabled && !password.val()){ alert("비밀번호를 입력해주세요."); returnFlag = false; } - if(!passwordConfirm){ + if(!password[0].disabled && !passwordConfirm.val()){ alert("비밀번호 확인을 입력해주세요."); returnFlag = false; } - if(returnFlag && password !== passwordConfirm){ - alert("비밀번호가 같지 않습니다."); - returnFlag = false; - } - if(!$("#name").val()){ + if(!name){ alert("이름 입력해주세요."); returnFlag = false; } + if(returnFlag){ + const passwordReg = /^(?=.*[a-zA-z])(?=.*[0-9])(?=.*[$`~!@$!%*#^?&\\(\\)\-_=+]).{8,16}$/; + if(!password[0].disabled){ + if(!passwordReg.test(password.val())){ + alert("비밀번호 조건이 맞지 않습니다.") + returnFlag = false; + }else{ + if(password.val() !== passwordConfirm.val()){ + alert("비밀번호가 같지 않습니다."); + returnFlag = false; + } + } + } + } return returnFlag; } @@ -83,5 +152,42 @@ function setSearchCondition(){ } } function formReset(){ - document.getElementById('userInfoForm').reset(); + document.getElementById('userInfoInsert').reset(); +} + +function getUserSeq(){ + return $(".userInfoCheckBox:checked").val(); +} + +function getUserInfo(userSeq){ + if(userSeq !== undefined){ + $.ajax({ + url: '/admin/selectUserInfo', + data: {userSeq: userSeq}, + type: 'GET', + dataType:"html", + success: function(html){ + $("#userContent").empty().append(html) + }, + error:function(){ + + } + }); + } +} +function getCategoryRole(userSeq){ + if(userSeq !== undefined){ + /*$.ajax({ + url: '/admin/codeValue', + data: {category: category}, + type: 'GET', + dataType:"html", + success: function(data){ + $("#valueDiv").empty().append(data) + }, + error:function(){ + + } + });*/ + } } \ No newline at end of file diff --git a/src/main/resources/templates/admin/userInfo.html b/src/main/resources/templates/admin/userInfo.html new file mode 100644 index 0000000..c9ebc1c --- /dev/null +++ b/src/main/resources/templates/admin/userInfo.html @@ -0,0 +1,70 @@ + + +
+ +
+ +
+ +
+
+
+
+
+ + +
+
+ + +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+ + + +
+
+
+
+ +
\ No newline at end of file diff --git a/src/main/resources/templates/admin/userMgt.html b/src/main/resources/templates/admin/userMgt.html index 535384c..80e6add 100644 --- a/src/main/resources/templates/admin/userMgt.html +++ b/src/main/resources/templates/admin/userMgt.html @@ -8,9 +8,7 @@
-
- - +

사용자 관리

@@ -83,7 +81,7 @@ - + @@ -104,7 +102,7 @@ -
  • +
  • @@ -132,8 +130,10 @@ -
    - +
    +
    +

    왼쪽 목록에서 선택해주세요.

    +
    @@ -150,18 +150,24 @@