189 lines
6.3 KiB
Python
189 lines
6.3 KiB
Python
from werkzeug.security import generate_password_hash
|
|
|
|
from Utils.ValidateUtil import ValidateAttr, Validate
|
|
|
|
|
|
class VerifyInfo(object):
|
|
"""认证信息"""
|
|
name = ValidateAttr(field='name', default=None, type=str, error_info='企业名称异常', error_code=200)
|
|
code = ValidateAttr(field='code', default=None, type=str, error_info='统一社会信用代码异常', error_code=200)
|
|
legal_person = ValidateAttr(field='legal_person', default=None, type=str, error_info='法人姓名异常', error_code=200)
|
|
legal_person_id = ValidateAttr(field='legal_person_id', default=None, type=str, error_info='法人身份证号异常', error_code=200)
|
|
|
|
def dict_to_save(self, **kwargs):
|
|
""""""
|
|
_dict_ = {
|
|
"企业名称": self.name,
|
|
"统一社会信用代码": self.code,
|
|
"法人姓名": self.legal_person,
|
|
"法人身份证": self.legal_person_id,
|
|
}
|
|
|
|
if 'columns' in kwargs:
|
|
_dict_ = {key: _dict_[key] for key in kwargs['columns']}
|
|
|
|
return _dict_
|
|
|
|
|
|
class CompanyUser(object):
|
|
"""企业用户"""
|
|
cid = ValidateAttr(field='cid', type=str, length=8, error_info='企业ID异常', error_code=200)
|
|
name = ValidateAttr(field='name', type=str, default=None, error_info='企业名称异常', error_code=200)
|
|
email = ValidateAttr(field='email', func=Validate.email, error_info='邮箱格式异常', error_code=200)
|
|
pwd = ValidateAttr(field='pwd', func=Validate.password, error_info='密码强度异常', error_code=200)
|
|
avatar_id = ValidateAttr(field='avatar_id', type=str, length=24, error_info='头像ID异常', error_code=200)
|
|
verify_status = ValidateAttr(field='verify_status', type=str, in_list=["是", "否"], error_info='认证状态异常', error_code=200)
|
|
verify_info = ValidateAttr(field='verify_info', type=VerifyInfo, error_info='认证信息异常', error_code=200)
|
|
register_time = ValidateAttr(field='register_time', default=None, type=str, error_info='注册时间异常', error_code=200)
|
|
|
|
def dict_to_show(self, **kwargs):
|
|
""""""
|
|
_dict_ = {
|
|
"企业ID": self.cid,
|
|
"企业名称": '企业用户' if self.name is None else self.name,
|
|
"邮箱": self.email,
|
|
"认证状态": "已认证" if self.verify_status == "是" else "未认证",
|
|
"token": None
|
|
}
|
|
|
|
if 'columns' in kwargs:
|
|
_dict_ = {key: _dict_[key] for key in kwargs['columns']}
|
|
|
|
return _dict_
|
|
|
|
def dict_to_save(self, **kwargs):
|
|
"""存储对象"""
|
|
|
|
# 对象字段与实例字段的映射
|
|
keys_map = {
|
|
"cid": "企业ID",
|
|
"name": "企业名称",
|
|
"email": "邮箱",
|
|
"avatar_id": "头像fid",
|
|
"pwd": "密码",
|
|
"register_time": "注册时间",
|
|
"verify_status": "已认证",
|
|
"verify_info": "认证信息"
|
|
}
|
|
|
|
# 实例一个存储对象
|
|
_dict_ = dict()
|
|
|
|
# 实例字段列表
|
|
obj_keys = [key for key in self.__dict__.keys()]
|
|
|
|
# 实例的值循环赋值给存储对象
|
|
for key in obj_keys:
|
|
_dict_[keys_map[key]] = self.__dict__[key]
|
|
|
|
# 存储对象子集
|
|
if 'columns' in kwargs:
|
|
_dict_ = {key: _dict_[key] for key in kwargs['columns']}
|
|
|
|
if '密码' in _dict_:
|
|
_dict_['密码'] = generate_password_hash(_dict_['密码'])
|
|
|
|
return _dict_
|
|
|
|
def login(self):
|
|
"""登录"""
|
|
|
|
def register(self, **kwargs):
|
|
"""注册"""
|
|
|
|
def get_company_user_info(self):
|
|
"""获取企业用户信息"""
|
|
|
|
def get_avatar(self):
|
|
"""获取用户头像"""
|
|
|
|
def change_avatar(self, **kwargs):
|
|
"""修改用户头像"""
|
|
|
|
def change_password(self, **kwargs):
|
|
"""修改登录密码"""
|
|
|
|
def change_email(self, **kwargs):
|
|
"""修改登录邮箱"""
|
|
|
|
|
|
class IDCardFront(object):
|
|
"""身份证正面"""
|
|
name = ValidateAttr()
|
|
gender = ValidateAttr()
|
|
nationality = ValidateAttr()
|
|
birth = ValidateAttr()
|
|
address = ValidateAttr()
|
|
id_num = ValidateAttr()
|
|
|
|
|
|
class IDCardBack(object):
|
|
"""身份证反面"""
|
|
issuing_authority = ValidateAttr()
|
|
validity_period = ValidateAttr()
|
|
|
|
|
|
class BusinessLicense(object):
|
|
"""营业执照"""
|
|
reg_num = ValidateAttr()
|
|
name = ValidateAttr()
|
|
capital = ValidateAttr()
|
|
type = ValidateAttr()
|
|
establish_date = ValidateAttr()
|
|
person = ValidateAttr()
|
|
business = ValidateAttr()
|
|
address = ValidateAttr()
|
|
|
|
|
|
class VerifyMaterial(object):
|
|
"""认证材料"""
|
|
|
|
cid = ValidateAttr(field='cid', type=str, length=8, error_info='企业ID异常', error_code=200)
|
|
image = ValidateAttr(field='image', func=Validate.image, error_info='图片格式异常', error_code=200)
|
|
verify_status = ValidateAttr(field='verify_status', type=str, in_list=["是", "否"], error_info='认证状态异常', error_code=200)
|
|
|
|
def upload_id_card(self):
|
|
"""上传身份证"""
|
|
|
|
def upload_business_license(self):
|
|
"""上传营业执照"""
|
|
|
|
|
|
class CompanyVerifyThreeFactors(object):
|
|
"""企业认证三要素"""
|
|
cid = ValidateAttr(field='cid', type=str, length=8)
|
|
code = ValidateAttr(field='code', type=str)
|
|
name = ValidateAttr(field='name', type=str)
|
|
legal_person = ValidateAttr(field='legal_person', type=str)
|
|
|
|
fields_map = {
|
|
"cid": "企业ID",
|
|
"code": "统一社会信用代码",
|
|
"name": "企业名称",
|
|
"legal_person": "法人姓名",
|
|
}
|
|
|
|
def company_verify(self):
|
|
"""企业认证"""
|
|
|
|
|
|
class EmailVerifyCodeRecord(object):
|
|
"""用户邮件通知"""
|
|
|
|
email = ValidateAttr(field='email', func=Validate.email, error_info='邮箱格式异常', error_code=200)
|
|
v_period = ValidateAttr(field='v_period', type=float, error_info='验证有效期格式异常', error_code=200)
|
|
v_code = ValidateAttr(field='v_code', type=str, length=6, error_info='验证码格式异常', error_code=200)
|
|
v_type = ValidateAttr(field="v_type", type=str, in_list=["register", "resetemail", "resetpwd"], error_info="邮件验证类型错误", error_code=200)
|
|
|
|
def dict_to_save(self):
|
|
""""""
|
|
_dict_ = {
|
|
"邮箱": self.email,
|
|
"验证有效期": self.v_period,
|
|
"验证码": self.v_code
|
|
}
|
|
return _dict_
|
|
|
|
def send_email(self):
|
|
"""发送邮件"""
|