用户登录 更改到v0.21版本

This commit is contained in:
王思川 2022-03-30 04:58:12 +08:00
parent d06cf544e2
commit e773befc38
1 changed files with 36 additions and 8 deletions

View File

@ -24,6 +24,8 @@ def create_user_impl(email, name, pwd, role):
执行成功 bool True
执行失败 str 异常信息
"""
db = MongoHelper("tfse_v0.21")
def check_params():
"""
参数检查
@ -38,7 +40,14 @@ def create_user_impl(email, name, pwd, role):
if not check_pwd_fmt(pwd):
return "密码格式错误"
if len(FIND_DATA("用户", "用户信息", {"email": email})) > 0:
email_is_existed = db.find_single_column(
"管理端",
"用户",
{"email": email},
"email"
)
if email_is_existed:
return "邮箱已被注册"
return True
@ -67,14 +76,21 @@ def create_user_impl(email, name, pwd, role):
若新ID可使用返回新ID
"""
new_id = make_id(8)
case = FIND_DATA("用户", "用户信息", {"企业ID": new_id}) is []
case = db.find_single_column(
"管理端",
"用户",
{"UID": new_id},
"UID"
) is not None
while case:
new_id = make_id(8)
return new_id
return gen_id()
def start_impl():
def __main__():
"""
执行流程
"""
@ -91,11 +107,16 @@ def create_user_impl(email, name, pwd, role):
user['role'] = role
user['create_time'] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
INSERT_DATA("用户", "用户信息", user)
db.upsert_single_data(
"管理端",
"用户",
{"UID": user['UID']},
user
)
return True
return start_impl()
return __main__()
def login_impl(email, pwd, vcode):
@ -230,10 +251,17 @@ def send_vcode_to_user_impl(email):
"recipients": [email],
"msg_body": "{}的验证码为 【{}5分钟内有效。".format("登录", vcode)}
requests.post(url=email_api + '/send_mail', headers=headers, data=json.dumps(data))
UPSERT_DATA('用户', '验证记录', {"email": email}, {"vcode": vcode, "timestamp": timestamp})
db = MongoHelper("tfse_v0.21")
db.upsert_single_data(
"管理端",
"邮箱验证码记录",
{"email": email},
{"vcode": vcode, "timestamp": timestamp}
)
return True
def start_impl():
def __main__():
res = check_param()
if res is not True:
return res
@ -244,7 +272,7 @@ def send_vcode_to_user_impl(email):
return True
return start_impl()
return __main__()
def list_user_impl(criteria, skip, limit):