def login(json_dict): email = json_dict["email"] password = json_dict["password"] with get_session() as s: user = User.get_by_email(s, email) if not user: return failed(msg="邮箱或密码不对") user = User.login(s, email, password) if not user: return failed(msg="邮箱或密码不对") return succeed(msg="登录成功", data={"token": user.token})
def login(): json_dict = g.json_dict email = json_dict["email"] password = json_dict["password"] with get_session() as s: user = User.get_by_email(s, email) if not user: return failed(msg="邮箱或密码不对=_=") user = User.login(s, email, password) if not user: return failed(msg="邮箱或密码不对。。") session["token"] = user.token return succeed(msg="登录成功", data={"token": user.token})
def register(json_dict): email = json_dict["email"] password = json_dict["password"] with get_session() as s: user = User.get_by_email(s, email) if user: return failed(msg="用户已经存在") user = User.register(s, email, email, password) return succeed(msg="注册成功,请认证")
def add(): s = g.mysql_session user = g.user user_invitation_count = UserInvitation.count_of_user(s, user.id) if user_invitation_count >= 10: return failed(code=402, msg="邀请码个数已超上限") user_invitation_code = UserInvitation.add(s, user.id) return succeed(msg="已成功生成", data=dict( code=user_invitation_code.code, is_used=0, ))
def register(): json_dict = g.json_dict json_dict = signup_schema.load(json_dict) email = json_dict["email"] nickname = json_dict["nickname"] password = json_dict["password"] invitation_code = json_dict["invitation_code"] with get_session() as s: invitation = UserInvitation.get_by_code(s, invitation_code) if invitation is None or invitation.is_used: return failed(msg="邀请码无效") user = User.register(s, nickname, email, password) # 邀请码置位 invitation.used_by_user(user.id) return succeed(msg="注册成功")