Kaynağa Gözat

web member password change

shjung 3 yıl önce
ebeveyn
işleme
0b91843365

+ 1 - 12
src/main/java/com/its/op/dto/its/oper/TbMsWebMemberDto.java

@@ -178,21 +178,10 @@ public class TbMsWebMemberDto implements Serializable {
         }
 
         public TbMsWebMember toEntity() {
-            AES256Util aes = null;
-            String encodePassword = "";
-            try {
-                aes = new AES256Util(AES256Util.DEFAULT_KEY);
-                encodePassword = aes.aesEncode(this.password); // 암호화
-                //decodePassword = aes.aesDecode(password); // 복호화
-            } catch (UnsupportedEncodingException e) {
-                encodePassword = this.password;
-            } catch (Exception e) {
-                encodePassword = this.password;
-            }
             return TbMsWebMember.builder()
                     .email(this.email)
                     .username(this.username)
-                    .password(encodePassword)
+                    .password(this.password)
                     .contactnum(this.contactnum)
                     .userauth(this.userauth)
                     .question(this.question)

+ 24 - 12
src/main/java/com/its/op/entity/its/oper/TbMsWebMember.java

@@ -75,6 +75,10 @@ public class TbMsWebMember implements Serializable {
     @Column(name = "DEL_YN", columnDefinition = "CHAR", length = 1)
     private String delYn;
 
+    public String getPassword() {
+        return this.password;
+    }
+
     public void setAccountLockFree() {
         this.loginFailCount = 0;
         this.isAccountLock = "N";
@@ -97,21 +101,10 @@ public class TbMsWebMember implements Serializable {
     }
 
     public void updateInfo(TbMsWebMemberDto.TbMsWebMemberUpdReq req) {
-        AES256Util aes = null;
-        String encodePassword = "";
-        try {
-            aes = new AES256Util(AES256Util.DEFAULT_KEY);
-            encodePassword = aes.aesEncode(req.getPassword()); // 암호화
-            //decodePassword = aes.aesDecode(password); // 복호화
-        } catch (UnsupportedEncodingException e) {
-            encodePassword = req.getPassword();
-        } catch (Exception e) {
-            encodePassword = req.getPassword();
-        }
 
         this.email = req.getEmail();
         this.username = req.getUsername();
-        this.password = encodePassword;
+        setPassword(req.getPassword());
         this.contactnum = req.getContactnum();
         this.userauth = req.getUserauth();
         this.question = req.getQuestion();
@@ -123,4 +116,23 @@ public class TbMsWebMember implements Serializable {
         this.delYn = req.getDelYn();
     }
 
+    public void setPassword(String password) {
+        if (this.password != password) {
+            this.password = encodePassword(password);
+        }
+    }
+    public String encodePassword(String password) {
+        AES256Util aes = null;
+        String encodePassword = "";
+        try {
+            aes = new AES256Util(AES256Util.DEFAULT_KEY);
+            encodePassword = aes.aesEncode(this.password); // 암호화
+            //decodePassword = aes.aesDecode(password); // 복호화
+        } catch (UnsupportedEncodingException e) {
+            encodePassword = this.password;
+        } catch (Exception e) {
+            encodePassword = this.password;
+        }
+        return encodePassword;
+    }
 }

+ 11 - 0
src/main/java/com/its/op/service/its/oper/TbMsWebMemberService.java

@@ -65,7 +65,18 @@ public class TbMsWebMemberService {
     public List<TbMsWebMemberDto> mergeInfoList(List<TbMsWebMemberDto.TbMsWebMemberUpdReq> reqList) {
         List<TbMsWebMemberDto> result = new ArrayList<>();
         for (TbMsWebMemberDto.TbMsWebMemberUpdReq req : reqList) {
+            TbMsWebMember entity = null;
+            try {
+                entity = requireOne(req.getEmail());
+            }
+            catch(NoSuchElementException e_notfound) {
+                entity = null;
+            }
+
             TbMsWebMember obj = req.toEntity();
+            if (entity != null) {
+                obj.setPassword(entity.getPassword());
+            }
             this.repo.save(obj);
             result.add(obj.toDto());
         }