he2802 4 年之前
父节点
当前提交
b7abad9428
共有 1 个文件被更改,包括 26 次插入2 次删除
  1. 26 2
      zhongzheng-admin/src/main/java/com/zhongzheng/controller/system/SysUserController.java

+ 26 - 2
zhongzheng-admin/src/main/java/com/zhongzheng/controller/system/SysUserController.java

@@ -6,6 +6,7 @@ import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import com.github.xiaoymin.knife4j.annotations.DynamicParameter;
 import com.github.xiaoymin.knife4j.annotations.DynamicParameters;
 import com.zhongzheng.common.annotation.Log;
+import com.zhongzheng.common.constant.Constants;
 import com.zhongzheng.common.constant.UserConstants;
 import com.zhongzheng.common.core.bo.SysUserEditBo;
 import com.zhongzheng.common.core.controller.BaseController;
@@ -15,9 +16,14 @@ import com.zhongzheng.common.core.domain.entity.SysUser;
 import com.zhongzheng.common.core.domain.model.LoginUser;
 import com.zhongzheng.common.core.page.TableDataInfo;
 import com.zhongzheng.common.enums.BusinessType;
+import com.zhongzheng.common.exception.CustomException;
+import com.zhongzheng.common.exception.user.UserPasswordNotMatchException;
+import com.zhongzheng.common.utils.MessageUtils;
 import com.zhongzheng.common.utils.SecurityUtils;
 import com.zhongzheng.common.utils.ServletUtils;
 import com.zhongzheng.common.utils.poi.ExcelUtil;
+import com.zhongzheng.framework.manager.AsyncManager;
+import com.zhongzheng.framework.manager.factory.AsyncFactory;
 import com.zhongzheng.framework.web.service.TokenService;
 import com.zhongzheng.modules.exam.domain.ExamConfig;
 import com.zhongzheng.modules.system.service.ISysPostService;
@@ -28,10 +34,15 @@ import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.security.authentication.AuthenticationManager;
+import org.springframework.security.authentication.BadCredentialsException;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.Authentication;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.annotation.Resource;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -57,6 +68,9 @@ public class SysUserController extends BaseController
     @Autowired
     private TokenService tokenService;
 
+    @Resource
+    private AuthenticationManager authenticationManager;
+
     /**
      * 获取用户列表
      */
@@ -182,9 +196,19 @@ public class SysUserController extends BaseController
             //重置密码
             if(!loginUser.getUser().isAdmin()){
                 //普通用户需传入旧密码修改
-                if(!loginUser.getPassword().equals(SecurityUtils.encryptPassword(bo.getOldPassword()))){
-                    return AjaxResult.error("旧密码错误"+loginUser.getPassword());
+                // 旧密码用户验证
+                Authentication authentication = null;
+                try
+                {
+                    // 该方法会去调用UserDetailsServiceImpl.loadUserByUsername
+                    authentication = authenticationManager
+                            .authenticate(new UsernamePasswordAuthenticationToken(loginUser.getUser().getUserName(), bo.getOldPassword()));
+                }
+                catch (Exception e)
+                {
+                    return AjaxResult.error("旧密码错误");
                 }
+
             }
             user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
         }