Bladeren bron

密码修改

zhangc 7 maanden geleden
bovenliggende
commit
731d27c21b

+ 1 - 6
src/main/java/com/sunxung/factoring/service/sys/UserService.java

@@ -122,14 +122,9 @@ public interface UserService {
 
     /**
      * 修改密码
-     *
-     * @param id
-     * @param password
-     * @param oldPassword
-     * @param password1
      * @return
      */
-    boolean updatePassword(Long id, String password, String oldPassword, String password1);
+    boolean updatePassword(String newPassword );
 
     /**
      * 禁用、启用用户

+ 24 - 23
src/main/java/com/sunxung/factoring/service/sys/impl/UserServiceImpl.java

@@ -321,34 +321,35 @@ public class UserServiceImpl implements UserService {
     }
 
     @Override
-    public boolean updatePassword(Long id, String password, String oldPassword, String password1) {
+    public boolean updatePassword(String password) {
         boolean bo = true;
-        if (id == null || id.equals("") || !password.equals(password1)) {
-            bo = false;
-            throw new ValidatorException(CodeUtil.FAIL, "修改密码失败");
-        }
-        User user = userMapper.get(id);
-        if (user == null) {
-            bo = false;
-            throw new ValidatorException(CodeUtil.FAIL, "修改密码失败");
-        }
-        if (!password.matches("[0-9A-Za-z]{6,16}")) {
-            bo = false;
-            throw new ValidatorException(CodeUtil.FAIL, "密码必须是6~16位数字和字母的组合!");
-        }
-        if (!PasswordUtil.validatePassword(oldPassword, user.getPassword())) {
-            bo = false;
-            throw new ValidatorException(CodeUtil.FAIL, "旧密码错误!");
-        }
+//        if (id == null || id.equals("") || !password.equals(password1)) {
+//            bo = false;
+//            throw new ValidatorException(CodeUtil.FAIL, "修改密码失败");
+//        }
+        Long userId = ThreadLocalUtil.getUserId();
+        User user = userMapper.get(userId);
+//        if (user == null) {
+//            bo = false;
+//            throw new ValidatorException(CodeUtil.FAIL, "修改密码失败");
+//        }
+//        if (!password.matches("[0-9A-Za-z]{6,16}")) {
+//            bo = false;
+//            throw new ValidatorException(CodeUtil.FAIL, "密码必须是6~16位数字和字母的组合!");
+//        }
+//        if (!PasswordUtil.validatePassword(oldPassword, user.getPassword())) {
+//            bo = false;
+//            throw new ValidatorException(CodeUtil.FAIL, "旧密码错误!");
+//        }
         if (bo == true && userMapper.resetPassword(user.getId(), PasswordUtil.createHash(password)) == 0) {
             bo = false;
             throw new ValidatorException(CodeUtil.FAIL, "用户密码修改失败!");
         }
-        try {
-            redisCache.flushAll();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
+//        try {
+//            redisCache.flushAll();
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//        }
         return bo;
     }
 

+ 13 - 16
src/main/java/com/sunxung/factoring/web/sys/UserController.java

@@ -15,10 +15,7 @@ import com.sunxung.factoring.service.sys.UserService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
 import java.util.List;
@@ -57,24 +54,24 @@ public class UserController {
     @RequestMapping(value = "/user/do_updateSimpleUser", method = RequestMethod.POST)
     @ResponseBody
     @OperationLog(operationModule = "用户信息",operationType = OperationTypeEnum.UPDATE,description = "个人信息修改")
-    public Object do_userInfoUpdate(User user) {
+    public Object do_userInfoUpdate(@RequestBody User user) {
         return userService.updateSimpleUserInfo(user);
     }
 
-    /**
-     * 修改密码
-     */
-    @RequestMapping("/user/updatePassword")
-    public String currSetPassword(Model model) {
-        model.addAttribute("userId", ThreadLocalUtil.getUserId());
-        return PREFIX + "updatePassword";
-    }
+//    /**
+//     * 修改密码
+//     */
+//    @RequestMapping("/user/updatePassword")
+//    public String currSetPassword(Model model) {
+//        model.addAttribute("userId", ThreadLocalUtil.getUserId());
+//        return PREFIX + "updatePassword";
+//    }
 
-    @RequestMapping(value = "/user/do_updatePassword", method = RequestMethod.POST)
+    @RequestMapping(value = "/user/updatePassword/{newPwd}", method = RequestMethod.PUT)
     @ResponseBody
     @OperationLog(operationModule = "用户信息",operationType = OperationTypeEnum.UPDATE,description = "修改密码")
-    public Object do_updatePassword(Long id, String password, String oldPassword, String password1) {
-        return userService.updatePassword(id, password, oldPassword, password1);
+    public Object do_updatePassword(@PathVariable("newPwd") String pwd) {
+        return userService.updatePassword(pwd);
     }
 
     @RequestMapping("/user/isAgreement")