示例#1
0
    def post(self):
        data = request.values

        if data["username"]:
            if Users.query.filter_by(username=data["username"]).first():
                return falseReturn("用户已存在")
            else:
                user = Users(username=data["username"],
                             password=Users.set_password(
                                 Users, data["password"]))
                db.session.add(user)
                db.session.commit()
                if user.id:
                    return Auth.authenticate(Auth, data["username"],
                                             data["password"])
                else:
                    return falseReturn("注册失败")
                # if verify(data):
                #     user = Users(
                #         username=data["username"],
                #         password=Users.set_password(Users, data["password"])
                #     )
                #     db.session.add(user)
                #     db.session.commit()
                #     if user.id:
                #         return Auth.authenticate(Auth, data["username"], data["password"])
                #     else:
                #         return falseReturn("注册失败")
                # else:
                #     return falseReturn("验证码错误")
        else:
            return falseReturn("请输入用户名")
示例#2
0
 def post(self):
     data = request.values
     username = data["username"]
     password = data["password"]
     if not username or not password:
         return falseReturn("用户名和密码不能为空")
     else:
         return Auth.authenticate(Auth, username, password)