ソースを参照

增加身份证字段。对重置密码生成8位密码用规则生成

xusl 1 年間 前
コミット
5ee87dbeae

+ 41 - 9
backend/src/main/java/com/jiayue/ssi/controller/SysUserController.java

@@ -1,6 +1,7 @@
 package com.jiayue.ssi.controller;
 
 import cn.hutool.core.lang.Validator;
+import cn.hutool.core.util.IdcardUtil;
 import cn.hutool.core.util.NumberUtil;
 import cn.hutool.crypto.SmUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -123,6 +124,7 @@ public class SysUserController {
                         record.setMailbox(AesUtils.decryptStr(record.getMailbox()));
                         record.setPhonenumber(AesUtils.decryptStr(record.getPhonenumber()));
                         record.setNickname(AesUtils.decryptStr(record.getNickname()));
+                        record.setIdcard(AesUtils.decryptStr(record.getIdcard()));
                     }
             );
             return ResponseVO.success(result);
@@ -181,6 +183,12 @@ public class SysUserController {
                 }
             }
 
+            if (!IdcardUtil.isValidCard(user.getIdcard())) {
+                return ResponseVO.fail("身份证无效!");
+            }
+            // 加密邮箱
+            user.setIdcard(AesUtils.encryptHex(user.getIdcard()).toUpperCase());
+
             if (StringUtils.isEmpty(user.getPhonenumber())) {
                 return ResponseVO.fail("手机号码不能为空!");
             } else if (!Validator.isMobile(user.getPhonenumber())) {
@@ -206,12 +214,22 @@ public class SysUserController {
                 return ResponseVO.fail("请输入正确的邮箱地址!");
             } else if (user.getMailbox().length() > 50) {
                 return ResponseVO.fail("邮箱长度不能超过50个字符!");
-            } else if (sysUserService.queryMailBox(user.getMailbox()) != null) {
-                return ResponseVO.fail(user.getMailbox() + "邮箱已存在!");
             }
             // 加密邮箱
             user.setMailbox(AesUtils.encryptHex(user.getMailbox()).toUpperCase());
 
+            if (user.getExpDate()!=null){
+                // 判断临时账号有效期不能超过30天
+                Calendar calendar = Calendar.getInstance();
+                // 将当前日期增加30天
+                calendar.add(Calendar.DAY_OF_MONTH, 29);
+                // 获取增加30天后的日期
+                Date endDate = calendar.getTime();
+                if (!user.getExpDate().before(endDate)){
+                    return ResponseVO.fail("账号有效期不能超过30天!");
+                }
+            }
+
             boolean bo = sysUserService.save(user);
             if (bo) {
                 return ResponseVO.success("添加用户信息成功");
@@ -254,7 +272,6 @@ public class SysUserController {
                 return ResponseVO.fail("此记录存在未审批的操作,不能进行修改!");
             }
 
-
             if (StringUtils.isEmpty(user.getUsername()) || StringUtils.isEmpty(user.getUsername().trim())) {
                 return ResponseVO.fail("用户账号不能为空!");
             } else{
@@ -272,16 +289,18 @@ public class SysUserController {
                 }
             }
 
+            if (!IdcardUtil.isValidCard(user.getIdcard())) {
+                return ResponseVO.fail("身份证无效!");
+            }
+            // 加密邮箱
+            user.setIdcard(AesUtils.encryptHex(user.getIdcard()).toUpperCase());
+
             if (StringUtils.isEmpty(user.getMailbox())) {
                 return ResponseVO.fail("邮箱不能为空!");
             } else if (!Validator.isEmail(user.getMailbox())) {
                 return ResponseVO.fail("请输入正确的邮箱地址!");
             } else if (user.getMailbox().length() > 50) {
                 return ResponseVO.fail("邮箱长度不能超过50个字符!");
-            } else if (!existUser.getMailbox().equals(user.getMailbox())) {
-                if (sysUserService.queryMailBox(user.getMailbox()) != null) {
-                    return ResponseVO.fail(user.getMailbox() + "邮箱已存在!");
-                }
             }
             // 加密邮箱
             user.setMailbox(AesUtils.encryptHex(user.getMailbox()).toUpperCase());
@@ -313,6 +332,17 @@ public class SysUserController {
             if (user.getExpDate()==null) {
                 user.setExpDate(null);
             }
+            else{
+                // 判断临时账号有效期不能超过30天
+                Calendar calendar = Calendar.getInstance();
+                // 将当前日期增加30天
+                calendar.add(Calendar.DAY_OF_MONTH, 29);
+                // 获取增加30天后的日期
+                Date endDate = calendar.getTime();
+                if (!user.getExpDate().before(endDate)){
+                    return ResponseVO.fail("账号有效期不能超过30天!");
+                }
+            }
 
             boolean bo = sysUserService.updateUser(user);
             if (bo) {
@@ -354,9 +384,11 @@ public class SysUserController {
         if (sysUser == null) {
             return ResponseVO.fail("重置密码失败!");
         }
+
+        SysPolicy sysPolicy = sysPolicyService.getOne(new QueryWrapper<>());
         // 生成8位初始密码
-        String randomPwd = RandomPwd.getRandomPwd(8);
-        log.info("重置随机密码:"+randomPwd);
+        String randomPwd = RandomRulePwd.createPwd(sysPolicy.getPasswordRule());
+        log.info("用户名:"+sysUser.getUsername()+" 初始/重置密码:"+randomPwd);
         // 加密密码
         String sm3password = SmUtil.sm3(randomPwd).toUpperCase();
         // 签名

+ 4 - 0
backend/src/main/java/com/jiayue/ssi/entity/SysUser.java

@@ -28,6 +28,10 @@ public class SysUser extends BaseEntity implements UserDetails {
      */
     private String username;
     /**
+     * 身份证号
+     */
+    private String idcard;
+    /**
      * 用户密码
      */
     private String password;

+ 44 - 0
backend/src/main/java/com/jiayue/ssi/util/RandomRulePwd.java

@@ -0,0 +1,44 @@
+package com.jiayue.ssi.util;
+
+import cn.hutool.core.util.RandomUtil;
+import cn.hutool.core.util.StrUtil;
+
+/**
+* 初始/重置密码生成
+*
+* @author xsl
+* @since 2023/08/04
+*/
+public class RandomRulePwd {
+    private static final String upperStr="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+    private static final String lowerStr="abcdefghijklmnopqrstuvwxyz";
+    private static final String numStr="1234567890";
+    private static final String specialStr="!@#$%^&*()_-+=<>?/";
+    // 生成密码长度
+    private static int strLength=8;
+
+    public static String createPwd(String rule){
+        String randomString="";
+        if ("A,B,C".equals(rule)){
+            while (!(StrUtil.containsAny(randomString,upperStr.split("")) && StrUtil.containsAny(randomString,lowerStr.split("")) && StrUtil.containsAny(randomString,numStr.split("")))){
+                randomString = cn.hutool.core.util.RandomUtil.randomString(upperStr + lowerStr + numStr, strLength);
+            }
+        }
+        else if ("A,B,D".equals(rule)){
+            while (!(StrUtil.containsAny(randomString,upperStr.split("")) && StrUtil.containsAny(randomString,lowerStr.split("")) && StrUtil.containsAny(randomString,specialStr.split("")))){
+                randomString = cn.hutool.core.util.RandomUtil.randomString(upperStr + lowerStr + specialStr, strLength);
+            }
+        }
+        else if ("A,C,D".equals(rule)){
+            while (!(StrUtil.containsAny(randomString,upperStr.split("")) && StrUtil.containsAny(randomString,numStr.split("")) && StrUtil.containsAny(randomString,specialStr.split("")))){
+                randomString = cn.hutool.core.util.RandomUtil.randomString(upperStr + numStr + specialStr, strLength);
+            }
+        }
+        else if ("B,C,D".equals(rule)){
+            while (!(StrUtil.containsAny(randomString,lowerStr.split("")) && StrUtil.containsAny(randomString,numStr.split("")) && StrUtil.containsAny(randomString,specialStr.split("")))){
+                randomString = RandomUtil.randomString(lowerStr + numStr + specialStr, strLength);
+            }
+        }
+        return randomString;
+    }
+}

+ 1 - 0
backend/src/main/resources/mapper/system/SysUserMapper.xml

@@ -8,6 +8,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <id     property="id"       column="id"      />
         <result property="username"     column="username"    />
         <result property="nickname"     column="nickname"    />
+        <result property="idcard"     column="idcard"    />
         <result property="usertype"        column="usertype"        />
         <result property="signstr"        column="signstr"        />
         <result property="phonenumber"  column="phonenumber"  />

+ 32 - 14
ui/src/views/sysManager/userManager/index.vue

@@ -107,6 +107,7 @@
             <vxe-column type="radio" width="60"/>
             <vxe-table-column field="username" title="用户账号"/>
             <vxe-table-column field="nickname" title="用户姓名"/>
+            <vxe-table-column field="idcard" title="身份证号码"/>
             <vxe-table-column field="mailbox" title="用户邮箱"/>
             <vxe-table-column field="phonenumber" title="手机号码"/>
             <vxe-table-column field="status" title="用户状态" :formatter="statusFormat"/>
@@ -150,8 +151,8 @@
     </el-row>
 
     <!-- 添加或修改用户配置对话框 -->
-    <el-dialog :title="title" :visible.sync="open" width="650px" append-to-body>
-      <el-form ref="form" :model="form" :rules="rules" width="630px" label-width="80px">
+    <el-dialog :title="title" :visible.sync="open" width="750px" append-to-body>
+      <el-form ref="form" :model="form" :rules="rules" width="730px" label-width="100px">
         <el-row>
           <el-col :span="12">
             <el-form-item label="用户账号" prop="username">
@@ -179,6 +180,24 @@
         </el-row>
         <el-row>
           <el-col :span="12">
+            <el-form-item label="身份证号码" prop="idcard">
+              <el-input style="width: 220px" v-model="form.idcard" placeholder="请输入身份证号码" maxlength="18"/>
+            </el-form-item>
+          </el-col>
+          <el-col :span="12">
+            <el-form-item label="账号有效期">
+              <el-date-picker
+                value-format="yyyy-MM-dd"
+                v-model="form.expDate"
+                type="date"
+                placeholder="请选择账号有效期"
+                :picker-options="pickerOptions">
+              </el-date-picker>
+            </el-form-item>
+          </el-col>
+        </el-row>
+        <el-row>
+          <el-col :span="12">
             <el-form-item label="用户状态">
               <el-select style="width: 220px" v-model="form.status" placeholder="请选择状态">
                 <el-option
@@ -203,18 +222,6 @@
             </el-form-item>
           </el-col>
         </el-row>
-        <el-row>
-          <el-col :span="12">
-            <el-form-item label="截止日期">
-              <el-date-picker
-                value-format="yyyy-MM-dd"
-                v-model="form.expDate"
-                type="date"
-                placeholder="请选择截止日期">
-              </el-date-picker>
-            </el-form-item>
-          </el-col>
-        </el-row>
       </el-form>
       <div slot="footer" class="dialog-footer">
         <el-button type="primary" @click="submitForm">确 定</el-button>
@@ -273,9 +280,15 @@ export default {
   name: "User",
   data() {
     return {
+      pickerOptions:{
+        disabledDate(time){
+          return time.getTime()<Date.now()-8.64e7
+        }
+      },
       id: undefined,
       username: undefined,
       nickname: undefined,
+      idcard: undefined,
       phonenumber: undefined,
       mailbox: undefined,
       status: "0",
@@ -343,6 +356,10 @@ export default {
           {required: true, message: "用户姓名不能为空", trigger: "blur"},
           {min: 2, max: 20, message: '用户姓名长度必须介于 2 和 20 之间', trigger: 'blur'}
         ],
+        idcard: [
+          {required: true, message: "身份证号码不能为空", trigger: "blur"},
+          {min: 15, max: 18, message: '身份证号请输入15位或者18位', trigger: 'blur'}
+        ],
         mailbox: [
           {required: true, message: "邮箱不能为空", trigger: "blur"},
           {type: "email", message: "请输入正确的邮箱地址", trigger: ["blur", "change"]}
@@ -460,6 +477,7 @@ export default {
         id: undefined,
         username: undefined,
         nickname: undefined,
+        idcard: undefined,
         phonenumber: undefined,
         mailbox: undefined,
         status: "0",