shjung 2 ani în urmă
părinte
comite
9f71fa92cf

+ 22 - 13
src/main/java/com/its/op/service/its/oper/TbUserInfrService.java

@@ -58,11 +58,18 @@ public class TbUserInfrService {
         return entity.toDto();
     }
 
+    private boolean isChangedPwd(String org, String cur) {
+        return !org.equals(cur);
+    }
+
     // 데이터 변경
     @Transactional
     public TbUserInfrDto updateById(String id, TbUserInfrDto.TbUserInfrUpdReq req) {
         TbUserInfr entity = requireOne(id);
         entity.updateInfo(req);
+        if (isChangedPwd(entity.getPwd(), req.getPwd())) {
+            entity.updatePswd(SHA256Util.encrypt(req.getPwd()));
+        }
         this.repo.save(entity);
         return entity.toDto();
     }
@@ -72,9 +79,7 @@ public class TbUserInfrService {
     public List<TbUserInfrDto> mergeInfoList(List<TbUserInfrDto.TbUserInfrUpdReq> reqList) {
         List<TbUserInfrDto> result = new ArrayList<>();
         for (TbUserInfrDto.TbUserInfrUpdReq req : reqList) {
-            TbUserInfr obj = req.toEntity();
-            this.repo.save(obj);
-            result.add(obj.toDto());
+            result.add(mergeInfo(req.getUserId(), req));
         }
         return result;
     }
@@ -83,6 +88,19 @@ public class TbUserInfrService {
     @Transactional
     public TbUserInfrDto mergeInfo(String id, TbUserInfrDto.TbUserInfrUpdReq req) {
         TbUserInfr obj = req.toEntity();
+        String reqPwd = obj.getPwd();
+
+        try {
+            TbUserInfr entity = requireOne(req.getUserId());
+            if (isChangedPwd(entity.getPwd(), req.getPwd())) {
+                entity.updatePswd(SHA256Util.encrypt(req.getPwd()));
+            }
+        }
+        catch(NoSuchElementException e_notfound) {
+            // 데이터가 없는경우 비밀번호 무조건 암호화
+            obj.updatePswd(SHA256Util.encrypt(req.getPwd()));
+        }
+
         this.repo.save(obj);
         return obj.toDto();
     }
@@ -112,15 +130,6 @@ public class TbUserInfrService {
         return result;
     }
 
-    /**
-     * 클라이언트 단에서 암호화 한값을 다시 복호화
-     * @param pswd
-     * @return
-     */
-    public String encoding(String pswd) {
-        return pswd;
-    }
-
     // 운영자 비밀번호 변경
     @Transactional
     public TbUserInfrDto updatePswdById(String id, TbUserInfrDto.TbUserPswdUpdReq req) throws NoSuchElementException {
@@ -130,7 +139,7 @@ public class TbUserInfrService {
         /**
          * 클라이언트 단에서 비밀번호 암호화 한 경우
          */
-        String orgPswd = encoding(req.getPwd());
+        String orgPswd = req.getPwd();
         if (req.getOldPwd().equals(orgPswd)) {
             // 비밀번호를 변경하지 않은 것임.(getPwd() => 암화화된 비밀번호가 들어가 있음)
             throw new NoSuchElementException("현재 비빌번호와 같습니다[1]: " + id);