import re from Utils.ErrorUtil import ReturnConditionCheckFailed from user.user_utils import decrypt_data class User: """管理端用户""" def __init__(self): self.uid = None # 用户ID str self.email = None # 邮箱 str self.name = None # 用户名 str self.pwd = None # 密码 str self.status = None # 用户状态 str self.role = None # 角色 str self.create_time = None # 创建时间 str def create(self): """创建新用户""" def check_uid(self): """用户ID校验""" if type(self.uid) is not str: raise ReturnConditionCheckFailed("用户ID格式错误", 200) if len(self.uid) != 8: raise ReturnConditionCheckFailed("用户ID格式错误", 200) 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 ReturnConditionCheckFailed("邮箱格式错误", 200) def check_name(self): """用户名格式校验""" if type(self.name) is not str: raise ReturnConditionCheckFailed("用户名格式错误", 200) def check_pwd(self): """密码格式校验""" if type(self.pwd) is not str: raise ReturnConditionCheckFailed("密码格式错误", 200) password = decrypt_data(encrypt_msg=self.pwd) if not password: raise ReturnConditionCheckFailed("密码格式错误", 200) 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 ReturnConditionCheckFailed("密码格式错误", 200) def check_status(self): """用户状态校验""" if self.status not in ['normal', 'disable']: raise ReturnConditionCheckFailed("用户状态格式错误", 200) def check_role(self): """用户角色校验""" if self.role not in ['admin', 'analysts', 'developer', 'operator', 'guest']: raise ReturnConditionCheckFailed("用户角色格式错误", 200) def check_user_obj(self, columns): """对象字段校验""" for column in columns: if column == "uid": self.check_uid() elif column == "email": self.check_email() elif column == "name": self.check_name() elif column == "pwd": self.check_pwd() elif column == "status": self.check_status() elif column == "role": self.check_role() else: pass def trans_status(self): """用户状态转换成前端显示格式""" return "正常" if self.status == "normal" else "停用" def trans_role(self): """用户角色转换成前端显示格式""" role_map = {"admin": "管理员", "analysts": "分析师", "developer": "开发者", "operator": "运营人员", "guest": "访客"} return role_map[self.role] def dict_to_save(self, **kwargs): """存储对象""" user_dict = { "UID": self.uid, "email": self.email, "name": self.name, "pwd": self.pwd, "status": self.status, "role": self.role, "create_time": self.create_time } if 'columns' in list(kwargs.keys()): user_dict = {key: user_dict for key in kwargs['columns']} return user_dict def dict_to_show(self, **kwargs): """显示对象""" user_dict = { "uid": self.uid, "邮箱": self.email, "姓名": self.name, "状态": self.trans_status(), "角色": self.trans_role(), "创建时间": self.create_time } if 'columns' in list(kwargs.keys()): user_dict = {key: user_dict for key in kwargs['columns']} return user_dict class ListUser(User): """查询用户列表""" def __init__(self, search, sort, page_size, page_no): super().__init__() self.search = search self.sort = sort self.page_size = page_size self.page_no = page_no class UserManage(User): """ 用户管理 """ @staticmethod def list_user(search, sort, page_size, page_no): """ 查询用户列表 """ def send_vcode_to_user(self): """ 发送验证码 Returns: 发送成功 bool 返回True 发送失败 str 返回异常信息 """ def disable_user(self): """ 禁用用户 """ # TODO def delete_user(self): """ 删除用户 """ # TODO def manage_role_of_user(self): """ 管理用户角色 """ # TODO class UserOperation(User): """ 用户操作 """ def __init__(self): super().__init__() self.token = None self.block = None self.vcode = None # 登录 def login(self): """ 用户登录 """ # 停用 def deactivate(self): """停用""" # return UserOperateImpl.disable_user_impl(self.uid) # 删除 def delete(self): """删除""" # return UserOperateImpl.delete_user_impl(self.uid) # 管理角色 def manage(self): """管理角色""" # return UserOperateImpl.manage_role_of_user_impl(self.uid, self.role)