From 2f8fc492f893bc9f6b47af939a843f7f883bbf35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EC=84=9D=20=EC=B5=9C?= Date: Fri, 24 Dec 2021 11:40:54 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B0=9C=EC=9D=B8=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=A7=80=20=EB=B9=84=EB=B0=80=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EB=B3=80=EA=B2=BD=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kcgfilemanager/config/SecurityConfig.java | 2 +- .../controller/BaseController.java | 24 +------ .../controller/InfoController.java | 36 ++++++++++ .../dbnt/kcgfilemanager/model/UserInfo.java | 2 + .../service/UserInfoService.java | 11 +++ src/main/resources/static/js/user/info.js | 56 +++++++++++++++ .../templates/admin/userCategoryRole.html | 4 +- .../resources/templates/fragments/header.html | 2 +- src/main/resources/templates/user/myInfo.html | 72 ++++++++++++------- 9 files changed, 158 insertions(+), 51 deletions(-) create mode 100644 src/main/java/com/dbnt/kcgfilemanager/controller/InfoController.java diff --git a/src/main/java/com/dbnt/kcgfilemanager/config/SecurityConfig.java b/src/main/java/com/dbnt/kcgfilemanager/config/SecurityConfig.java index 5f42d2b..02189cc 100644 --- a/src/main/java/com/dbnt/kcgfilemanager/config/SecurityConfig.java +++ b/src/main/java/com/dbnt/kcgfilemanager/config/SecurityConfig.java @@ -34,7 +34,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() // 페이지 권한 설정 .antMatchers("/board/**").hasRole(Role.USER.name()) // USER, ADMIN 접근 허용 - .antMatchers("/info").hasRole(Role.USER.name()) // USER, ADMIN 접근 허용 + .antMatchers("/info/**").hasRole(Role.USER.name()) // USER, ADMIN 접근 허용 .antMatchers("/admin/**").hasRole(Role.ADMIN.name()) // ADMIN만 접근 허용 .antMatchers("/user/login").permitAll() // 로그인 페이지는 권한 없이 접근 허용 .and() // 로그인 설정 diff --git a/src/main/java/com/dbnt/kcgfilemanager/controller/BaseController.java b/src/main/java/com/dbnt/kcgfilemanager/controller/BaseController.java index 5a77d3d..050048b 100644 --- a/src/main/java/com/dbnt/kcgfilemanager/controller/BaseController.java +++ b/src/main/java/com/dbnt/kcgfilemanager/controller/BaseController.java @@ -1,20 +1,15 @@ package com.dbnt.kcgfilemanager.controller; -import com.dbnt.kcgfilemanager.model.CategoryRole; import com.dbnt.kcgfilemanager.model.UserInfo; import com.dbnt.kcgfilemanager.service.BoardCategoryService; -import com.dbnt.kcgfilemanager.service.CategoryRoleService; import com.dbnt.kcgfilemanager.service.CommonCodeService; import lombok.RequiredArgsConstructor; -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.annotation.AuthenticationPrincipal; -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 @@ -22,18 +17,17 @@ public class BaseController { private final CommonCodeService commonCodeService; private final BoardCategoryService boardCategoryService; - private final CategoryRoleService categoryRoleService; @GetMapping("/") - public ModelAndView loginCheck(Principal principal, HttpSession session) { + public ModelAndView loginCheck(@AuthenticationPrincipal UserInfo loginUser, HttpSession session) { ModelAndView mav = null; - if(principal == null){ + if(loginUser == null){ mav = new ModelAndView("redirect:/user/login"); }else{ session.setAttribute("positionList", commonCodeService.selectCommonCodeValue("POSITION")); session.setAttribute("departmentList", commonCodeService.selectCommonCodeValue("DEPARTMENT")); session.setAttribute("categoryList", boardCategoryService.selectBoardCategoryAll(null, 1)); - if(((UserInfo)((UsernamePasswordAuthenticationToken) principal).getPrincipal()).getUserRole().indexOf("ADMIN")>0){ + if(loginUser.getUserRole().indexOf("ADMIN")>0){ mav = new ModelAndView("redirect:/admin/main"); }else{ mav = new ModelAndView("redirect:/board/main"); @@ -67,16 +61,4 @@ public class BaseController { ModelAndView mav = new ModelAndView("login/denied"); return mav; } - - @GetMapping("/info") - public ModelAndView goMyInfo(@AuthenticationPrincipal UserInfo loginUser) { - ModelAndView mav = new ModelAndView("user/myInfo"); - mav.addObject("loginUser", loginUser); - if(!loginUser.getUserRole().contains("ADMIN")){ - CategoryRole categoryRole = new CategoryRole(); - categoryRole.setUserSeq(loginUser.getUserSeq()); - mav.addObject("categorySeqList", categoryRoleService.selectCategorySeqListToUser(categoryRole)); - } - return mav; - } } diff --git a/src/main/java/com/dbnt/kcgfilemanager/controller/InfoController.java b/src/main/java/com/dbnt/kcgfilemanager/controller/InfoController.java new file mode 100644 index 0000000..afd3770 --- /dev/null +++ b/src/main/java/com/dbnt/kcgfilemanager/controller/InfoController.java @@ -0,0 +1,36 @@ +package com.dbnt.kcgfilemanager.controller; + +import com.dbnt.kcgfilemanager.model.CategoryRole; +import com.dbnt.kcgfilemanager.model.UserInfo; +import com.dbnt.kcgfilemanager.service.CategoryRoleService; +import com.dbnt.kcgfilemanager.service.UserInfoService; +import lombok.RequiredArgsConstructor; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.servlet.ModelAndView; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/info") +public class InfoController { + + private final CategoryRoleService categoryRoleService; + private final UserInfoService userInfoService; + + @GetMapping("/myInfo") + public ModelAndView myInfo(@AuthenticationPrincipal UserInfo loginUser) { + ModelAndView mav = new ModelAndView("user/myInfo"); + mav.addObject("loginUser", loginUser); + if(!loginUser.getUserRole().contains("ADMIN")){ + CategoryRole categoryRole = new CategoryRole(); + categoryRole.setUserSeq(loginUser.getUserSeq()); + mav.addObject("categorySeqList", categoryRoleService.selectCategorySeqListToUser(categoryRole)); + } + return mav; + } + + @PutMapping("/passwordModify") + public String passwordModify(@AuthenticationPrincipal UserInfo loginUser, UserInfo modifyInfo){ + return userInfoService.updatePassword(loginUser, modifyInfo); + } +} diff --git a/src/main/java/com/dbnt/kcgfilemanager/model/UserInfo.java b/src/main/java/com/dbnt/kcgfilemanager/model/UserInfo.java index b4ca676..2621f3c 100644 --- a/src/main/java/com/dbnt/kcgfilemanager/model/UserInfo.java +++ b/src/main/java/com/dbnt/kcgfilemanager/model/UserInfo.java @@ -44,6 +44,8 @@ public class UserInfo extends BaseModel implements UserDetails{ @Column(name = "USER_STATUS") private String userStatus; + @Transient + private String modifyPassword; @Transient private String positionName; @Transient diff --git a/src/main/java/com/dbnt/kcgfilemanager/service/UserInfoService.java b/src/main/java/com/dbnt/kcgfilemanager/service/UserInfoService.java index 17595a2..2dfca4e 100644 --- a/src/main/java/com/dbnt/kcgfilemanager/service/UserInfoService.java +++ b/src/main/java/com/dbnt/kcgfilemanager/service/UserInfoService.java @@ -39,6 +39,17 @@ public class UserInfoService implements UserDetailsService { return targetUserInfo.getUserId(); } + public String updatePassword(UserInfo loginUser, UserInfo modifyInfo){ + Pbkdf2PasswordEncoder passwordEncoder = new Pbkdf2PasswordEncoder(); + if(passwordEncoder.matches(modifyInfo.getPassword(), loginUser.getPassword())){ + loginUser.setPassword(convertPassword(modifyInfo.getModifyPassword())); + userInfoRepository.save(loginUser); + return "OK"; + }else{ + return "passwordNotMatch"; + } + } + private String convertPassword(String password){ Pbkdf2PasswordEncoder passwordEncoder = new Pbkdf2PasswordEncoder(); return passwordEncoder.encode(password); diff --git a/src/main/resources/static/js/user/info.js b/src/main/resources/static/js/user/info.js index 90548e7..487df97 100644 --- a/src/main/resources/static/js/user/info.js +++ b/src/main/resources/static/js/user/info.js @@ -8,6 +8,62 @@ $(document).on('click', '#moveRightBtn', function (){ $(document).on('click', '#moveLeftBtn', function (){ moveCategorySelectBody(-1); }) +$(document).on('click', '#savePasswordBtn', function (){ + if(passwordCheck()){ + const formData = new FormData($("#modifyPasswordForm")[0]); + $.ajax({ + type : 'PUT', + data : formData, + url : "/info/passwordModify", + processData: false, + contentType: false, + success : function(result) { + if(result==="OK"){ + alert("수정되었습니다."); + $("#passwordModifyModal").find(".btn-close").click(); + }else if(result==="passwordNotMatch"){ + alert("현재 비밀번호가 맞지 않습니다."); + } + }, + error : function(xhr, status) { + + } + }) + } +}) + +function passwordCheck(){ + let returnFlag = true; + const password = $("#password"); + const modifyPassword =$("#modifyPassword"); + const passwordConfirm = $("#passwordConfirm"); + if(!password.val()){ + alert("비밀번호를 입력해주세요."); + returnFlag = false; + } + if(!modifyPassword.val()){ + alert("새 비밀번호를 입력해주세요."); + returnFlag = false; + } + if(!passwordConfirm.val()){ + alert("비밀번호 확인을 입력해주세요."); + returnFlag = false; + } + if(returnFlag){ + const passwordReg = /^(?=.*[a-zA-z])(?=.*[0-9])(?=.*[$`~!@$!%*#^?&\\(\\)\-_=+]).{8,16}$/; + if(!passwordReg.test(modifyPassword.val())){ + alert("비밀번호 조건이 맞지 않습니다.") + returnFlag = false; + }else{ + if(modifyPassword.val() !== passwordConfirm.val()){ + alert("비밀번호가 같지 않습니다."); + returnFlag = false; + } + } + } + return returnFlag; + +} function moveCategorySelectBody(direction){ const categorySelectBody = $("#categorySelectBody"); diff --git a/src/main/resources/templates/admin/userCategoryRole.html b/src/main/resources/templates/admin/userCategoryRole.html index bcede14..7c40264 100644 --- a/src/main/resources/templates/admin/userCategoryRole.html +++ b/src/main/resources/templates/admin/userCategoryRole.html @@ -2,8 +2,8 @@
-
-
+
+
diff --git a/src/main/resources/templates/fragments/header.html b/src/main/resources/templates/fragments/header.html index 2fee39f..a317b9d 100644 --- a/src/main/resources/templates/fragments/header.html +++ b/src/main/resources/templates/fragments/header.html @@ -8,7 +8,7 @@ diff --git a/src/main/resources/templates/user/myInfo.html b/src/main/resources/templates/user/myInfo.html index 4013480..b4175cb 100644 --- a/src/main/resources/templates/user/myInfo.html +++ b/src/main/resources/templates/user/myInfo.html @@ -11,8 +11,8 @@

개인정보

- - + +
@@ -70,19 +70,24 @@
+
+
+ +
+
-
권한정보
+
작성 권한
-
-
+
+
@@ -110,27 +115,6 @@ -
@@ -146,5 +130,41 @@
+
\ No newline at end of file