Browse Source

添加修改密码接口

fengyanjie 3 years ago
parent
commit
a68b7e164b

+ 7 - 0
dmp-rwd-edit/src/main/java/com/persagy/dmp/rwd/edit/controller/AdminUserController.java

@@ -11,6 +11,8 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.Map;
+
 @RestController
 @RequestMapping("/rwdedit/system/user")
 public class AdminUserController {
@@ -37,4 +39,9 @@ public class AdminUserController {
         return service.delete(param);
     }
 
+    @PostMapping(value = "/chgpwd")
+    public MapResponse chgpwd(@RequestBody Map<String, String> param) {
+        return service.chgpwd(param);
+    }
+
 }

+ 19 - 0
dmp-rwd-edit/src/main/java/com/persagy/dmp/rwd/edit/service/AdminUserService.java

@@ -13,6 +13,7 @@ import com.persagy.dmp.rwd.edit.entity.AdminUserProject;
 import com.persagy.dmp.rwd.edit.entity.QAdminUser;
 import com.persagy.dmp.rwd.edit.repository.AdminUserRepository;
 import com.querydsl.core.types.dsl.BooleanExpression;
+import org.apache.commons.collections4.MapUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -20,6 +21,7 @@ import org.springframework.stereotype.Service;
 import javax.transaction.Transactional;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 @Service
@@ -139,5 +141,22 @@ public class AdminUserService {
         adminUserRepository.save(user);
         return response;
     }
+
+    public MapResponse chgpwd(Map<String, String> param) {
+        MapResponse resp = new MapResponse();
+
+        String oldPwd = MapUtils.getString(param, "oldPwd");
+        String newPwd = MapUtils.getString(param, "newPwd");
+
+        AdminUser user = adminUserRepository.findById(UserUtils.currentUserId()).get();
+
+        if (!user.getPassword().equalsIgnoreCase(MD5Utils.getSign(oldPwd))) {
+            resp.setFail("原密码错误");
+        } else {
+            user.setPassword(MD5Utils.getSign(newPwd));
+            adminUserRepository.save(user);
+        }
+        return resp;
+    }
 }