Forráskód Böngészése

重置密码后,默认为弱密码需要用户自己重新修改密码。

deason 1 éve
szülő
commit
9b038a44a4

+ 24 - 7
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/UserController.java

@@ -31,7 +31,6 @@ import com.google.common.collect.Maps;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang.StringEscapeUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
@@ -537,7 +536,7 @@ public class UserController extends ControllerSupport {
         trim(userForm, true);
         userForm.setId(null);
 
-        if(!BaseUtil.checkPassword(userForm.getPassword())){
+        if (!BaseUtil.checkPassword(userForm.getPassword())) {
             throw new StatusException("密码至少包含大写字母、小写字母、数字、特殊符号中的三种,且长度限制在6-10位!");
         }
 
@@ -742,26 +741,36 @@ public class UserController extends ControllerSupport {
                 throw new StatusException("150410", "超级管理员账号不允许修改");
             }
             UserEntity user = GlobalHelper.getEntity(userRepo, userId, UserEntity.class);
+            if (user == null) {
+                continue;
+            }
+
+            user.setPasswordWeak(true);
             user.setPassword(ByteUtil.toHexAscii(SHA256.encode(user.getLoginName() + BasicConsts.DEFAULT_PASSWORD)));
             userRepo.save(user);
         }
         User accessUser = getAccessUser();
         ReportsUtil.report(new AdminOperateReport(accessUser.getRootOrgId(), accessUser.getUserId(), AdminOperateType.TYPE8.getDesc(), "用户ID:" + id));
     }
-    
+
     @ApiOperation(value = "批量重置用户密码", notes = "重置密码")
     @PostMapping("/resetPass")
     @Transactional
     public void resetPassBatch(@RequestParam Long[] ids) {
-    	if(ids==null||ids.length==0) {
-    		throw new StatusException("用户ID不能为空");
-    	}
+        if (ids == null || ids.length == 0) {
+            throw new StatusException("用户ID不能为空");
+        }
         for (Long userId : ids) {
             if (isSuperAdmin(userId)) {
                 throw new StatusException("150410", "超级管理员账号不允许修改");
             }
             UserEntity user = GlobalHelper.getEntity(userRepo, userId, UserEntity.class);
+            if (user == null) {
+                continue;
+            }
+
             user.setPassword(ByteUtil.toHexAscii(SHA256.encode(user.getLoginName() + BasicConsts.DEFAULT_PASSWORD)));
+            user.setPasswordWeak(true);
             userRepo.save(user);
         }
         User accessUser = getAccessUser();
@@ -780,6 +789,10 @@ public class UserController extends ControllerSupport {
                 throw new StatusException("150410", "超级管理员账号不允许修改");
             }
             UserEntity user = GlobalHelper.getEntity(userRepo, userId, UserEntity.class);
+            if (user == null) {
+                continue;
+            }
+
             user.setEnable(true);
             userRepo.save(user);
             ret.add(user.getId() + ":" + user.getName());
@@ -801,6 +814,10 @@ public class UserController extends ControllerSupport {
                 throw new StatusException("150410", "超级管理员账号不允许修改");
             }
             UserEntity user = GlobalHelper.getEntity(userRepo, userId, UserEntity.class);
+            if (user == null) {
+                continue;
+            }
+
             user.setEnable(false);
             userRepo.save(user);
             ret.add(user.getId() + ":" + user.getName());
@@ -826,7 +843,7 @@ public class UserController extends ControllerSupport {
         // if (password.length() < 6) {
         //     throw new StatusException("150411", "密码长度至少6位");
         // }
-        if(!BaseUtil.checkPassword(password)){
+        if (!BaseUtil.checkPassword(password)) {
             throw new StatusException("密码至少包含大写字母、小写字母、数字、特殊符号中的三种,且长度限制在6-10位!");
         }