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):