From e773befc38e6eecbf09ac1f8a41e4cbedf722094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=9D=E5=B7=9D?= Date: Wed, 30 Mar 2022 04:58:12 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=99=BB=E5=BD=95=20?= =?UTF-8?q?=E6=9B=B4=E6=94=B9=E5=88=B0v0.21=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- user/user_impl.py | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/user/user_impl.py b/user/user_impl.py index 3c89c51..44355c4 100644 --- a/user/user_impl.py +++ b/user/user_impl.py @@ -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):