tfse-admin-api-v0.2/user/user_obj.py

165 lines
4.0 KiB
Python
Raw Normal View History

2022-03-31 07:00:37 +08:00
import re
from Utils.ErrorUtil import ObjColumnCheckError
from user.user_impl import UserManageImpl, UserOperateImpl
from user.user_utils import decrypt_data
2021-12-31 14:51:41 +08:00
class User:
2022-01-10 05:22:25 +08:00
"""
用户对象
2022-03-31 07:00:37 +08:00
uid: str 用户ID
email: str 邮箱
name: str 用户名
pwd: str 密码
status: str 用户状态
role: str 角色
2022-01-10 05:22:25 +08:00
"""
2021-12-31 14:51:41 +08:00
def __init__(self):
self.uid = None
2022-01-06 17:56:30 +08:00
self.email = None
2021-12-31 14:51:41 +08:00
self.name = None
2022-01-06 17:56:30 +08:00
self.pwd = None
2022-03-31 07:00:37 +08:00
self.status = None
2021-12-31 14:51:41 +08:00
self.role = None
2022-01-06 17:56:30 +08:00
2022-03-31 07:00:37 +08:00
def check_uid(self):
"""用户ID校验"""
if type(self.uid) is not str:
raise ObjColumnCheckError("用户ID格式错误")
if len(self.uid) != 8:
raise ObjColumnCheckError("用户ID格式错误")
def check_email(self):
"""邮箱格式仅允许@fecr.com.cn"""
regex = "^.+\\@fecr.com.cn"
case = (len(self.email) > 7) and (re.match(regex, self.email) is not None)
result = True if case else False
if not result:
raise ObjColumnCheckError("邮箱格式错误")
def check_name(self):
"""用户名格式校验"""
if type(self.name) is not str:
raise ObjColumnCheckError("用户名格式错误")
def check_pwd(self):
"""密码格式校验"""
if type(self.pwd) is not str:
raise ObjColumnCheckError("密码格式错误")
password = decrypt_data(encrypt_msg=self.pwd)
if not password:
raise ObjColumnCheckError("密码格式错误")
regex = "^(?![A-Za-z0-9]+$)(?![a-z0-9\\W]+$)(?![A-Za-z\\W]+$)(?![A-Z0-9\\W]+$)^.{8,}$"
case = (len(password) >= 8) and (re.match(regex, password) is not None)
result = True if case else False
if not result:
raise ObjColumnCheckError("密码格式错误")
def check_status(self):
"""用户状态校验"""
if self.status not in ['normal', 'disable']:
raise ObjColumnCheckError("用户状态格式错误")
def check_role(self):
"""用户角色校验"""
if self.role not in ['admin', 'analysts', 'developer', 'operator', 'guest']:
raise ObjColumnCheckError("用户角色格式错误")
2022-01-10 05:22:25 +08:00
class UserManage(User):
"""
用户管理
"""
2022-03-30 16:47:27 +08:00
@staticmethod
def list_user(search, sort, page_size, page_no):
"""
用户信息列表
"""
2022-03-31 07:00:37 +08:00
return UserManageImpl.list_user_impl(search, sort, page_size, page_no)
2022-03-30 16:47:27 +08:00
2022-01-26 15:07:18 +08:00
def send_vcode_to_user(self):
"""
发送验证码
Returns:
发送成功 bool 返回True
发送失败 str 返回异常信息
"""
2022-03-31 07:00:37 +08:00
self.check_email()
return UserManageImpl.send_vcode_to_user_impl(self.email)
2022-01-10 05:22:25 +08:00
2022-01-06 17:56:30 +08:00
def create_user(self):
2022-01-11 07:13:28 +08:00
"""
创建用户
Returns:
创建成功 bool 返回True
创建失败 str 返回异常信息
"""
2022-03-31 07:00:37 +08:00
return UserManageImpl.create_user_impl(self.email, self.name, self.pwd, self.role)
2022-01-10 05:22:25 +08:00
2022-01-26 15:07:18 +08:00
def disable_user(self):
"""
禁用用户
"""
# TODO
2022-01-10 05:22:25 +08:00
def delete_user(self):
2022-01-26 15:07:18 +08:00
"""
删除用户
"""
# TODO
2022-01-10 05:22:25 +08:00
2022-01-26 15:07:18 +08:00
def manage_role_of_user(self):
2022-01-11 15:12:08 +08:00
"""
2022-01-26 15:07:18 +08:00
管理用户角色
2022-01-11 15:12:08 +08:00
"""
2022-01-26 15:07:18 +08:00
# TODO
2022-01-11 15:12:08 +08:00
2022-01-10 05:22:25 +08:00
class UserOperation(User):
"""
用户操作
"""
2022-01-24 18:16:33 +08:00
def __init__(self):
super().__init__()
self.token = None
self.block = None
2022-01-25 16:48:42 +08:00
self.vcode = None
2022-01-24 18:16:33 +08:00
2022-01-10 05:22:25 +08:00
# 登录
def login(self):
2022-01-11 15:12:08 +08:00
"""
用户登录
"""
2022-03-31 07:00:37 +08:00
return UserOperateImpl.login_impl(self.email, self.pwd, self.vcode)
# 停用
def deactivate(self):
2022-03-31 07:00:37 +08:00
return UserOperateImpl.disable_user_impl(self.uid)
# 删除
def delete(self):
2022-03-31 07:00:37 +08:00
return UserOperateImpl.delete_user_impl(self.uid)
# 管理角色
def manage(self):
2022-03-31 07:00:37 +08:00
return UserOperateImpl.manage_role_of_user_impl(self.uid, self.role)
if __name__ == '__main__':
user = User()
user.email = "aaa"
user.check_email()