瀏覽代碼

账号过期

libushang 4 天之前
父節點
當前提交
0b325877eb
共有 3 個文件被更改,包括 16 次插入1 次删除
  1. 4 1
      models/ry_sys_base.py
  2. 4 0
      routers/prod_api/auth.py
  3. 8 0
      routers/prod_api/system/user/__init__.py

+ 4 - 1
models/ry_sys_base.py

@@ -4,7 +4,7 @@ from sqlalchemy.dialects.mysql import TINYINT
 from sqlalchemy.sql import func
 from sqlalchemy import event
 from database import Base
-from datetime import datetime
+from datetime import datetime, timedelta
 from common.enc import mpfun
 
 '''社会化关系表'''
@@ -125,6 +125,8 @@ class SysDept(Base):
 
 '''用户信息表'''
 
+def default_ten_year_later():
+    return datetime.now() + timedelta(days=3650)
 
 class SysUser(Base):
     __tablename__ = 'sys_user'
@@ -154,6 +156,7 @@ class SysUser(Base):
     remark = Column(String(500), default='', comment='备注')
     yzy_account = Column(String(50), default='', comment='粤政易账号')
     sign = Column(String, server_default='', default='', comment='HMACSM3数值')
+    expire_time = Column(DateTime, default=default_ten_year_later, comment='过期时间')
 
     @property
     def plain_user_name(self):

+ 4 - 0
routers/prod_api/auth.py

@@ -145,6 +145,10 @@ async def login(
         # 校验账号是否停用
         if row.status != "0":
             raise AppException(500, "帐号已停用")
+        
+        # 校验账号是否过期
+        if row.expire_time is not None and row.expire_time > datetime.now():
+            raise AppException(500, "帐号已过期")
 
         # 校验长期(超过1个月)未使用的账号和及开通后未及时(如72小时)修改初始密码的账号做清除
         login_date = row.login_date

+ 8 - 0
routers/prod_api/system/user/__init__.py

@@ -170,6 +170,11 @@ async def userupdate(
         yzyAccount = body['yzyAccount']
         status = body['status']
 
+        if 'expireTime' in body:
+            expire_time = body['expireTime']
+        else:
+            expire_time = None
+
         dept_info = dept_id_get_dept_info(db, deptId)
         deptName = dept_info.dept_name
 
@@ -186,6 +191,7 @@ async def userupdate(
         user.remark = remark
         user.yzy_account = yzyAccount
         user.status = status
+        user.expire_time = expire_time
         user.sign = ''
         db.commit()
         db.refresh(user)
@@ -819,6 +825,7 @@ async def userlist( #user_id_1: int = Query(None ,description='用户id'),
             "roles": user_roles,
             "sex": user.sex,
             "status": user.status,
+            "expireTime": user.expire_time,
             "updateBy":user.update_by,
             "updateTime": user.create_time.strftime('%Y-%m-%d %H:%M:%S') if user.create_time else None,
             "userId": user.user_id,
@@ -970,6 +977,7 @@ async def userlist( user_id_1: int = Query(None ,description='用户id'),
                 "createTime": user.create_time.strftime('%Y-%m-%d %H:%M:%S') if user.create_time else '',
                 "deptName": user.dept_name,
                 "yzyAccount": (user.yzy_account),
+                "expireTime": user.expire_time,
             }
 
         roles = get_role(db,roleIds)