Пример #1
0
def verify_token(token):
    s = Serializer(SECRET_KEY, expires_in=EXPIRATION_TIME)
    try:
        data = s.loads(token)
        g.user_id = data['user_id']
        return True
    except SignatureExpired:
        abort(make_result(code=Code.EXPIRED_TOKEN))  # valid token, but expired
    except BadSignature:
        abort(make_result(code=Code.INVALID_TOKEN))  # invalid token
Пример #2
0
 def post(self):
     rep = LoginApi().rep.parse_args(strict=True)
     user_name = rep.get('user_name')
     password = rep.get('password')
     user = User.query.filter_by(user_name=user_name).first()
     if user is None:
         abort(make_result(code=Code.ACCOUNT_NOFOUND))
     elif user.check_password(password) is False:
         abort(make_result(code=Code.LOGIN_FAILED))
     else:
         token = generate_auth_token(user.id)
         return make_result(data={"token": token.decode()})
Пример #3
0
def custom_abort(http_status_code, *args, **kwargs):
    """
    改写参数传递错误的返回格式
    :param http_status_code: 状态码
    :param args:
    :param kwargs:
    :return: 定义返回data
    """
    if http_status_code == 400:
        abort(make_result(code=Code.NO_PARAM))
    return abort(http_status_code)
Пример #4
0
def page_not_found(e):
    return (make_result(code=Code.SYSTEM_ERRCODE))
Пример #5
0
def my_abort(http_status_code, *args, **kwargs):
    if http_status_code == 400:
        abort(make_result(code=Code.PARAMS_ERRCODE))
Пример #6
0
def verify_error():
    abort(make_result(code=Code.AUTH_ERROR))
Пример #7
0
 def post(self):
     user_id = g.user_id
     name = User.query.filter_by(id=user_id).first().user_name
     return make_result(data={"name": name + "--真实玩家"})
Пример #8
0
 def get(self):
     req = IdTestApi().rep.parse_args(strict=True)
     id = req.get('id')
     return make_result(data={"id": id * 123})
Пример #9
0
 def get(self):
     req = parser.parse_args(strict=True)
     a = req.get("a")
     b = req.get("b")
     return make_result(data=str(a) + b)