decorators.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:heroku-python-boilerplate 作者: chavli 项目源码 文件源码
def require_token(func):
    """ verifies the uuid/token combo of the given account. account type can be:
        customer, fox, merchant """
    @wraps(func)
    def decorator(*args, **kwargs):
        if request.authorization:
            uuid = request.authorization.username
            token = request.authorization.password
            try:
                manager = SessionManager()
                valid = manager.verify(uuid, token)
                if not valid:
                    return UnauthorizedResponseJson().make_response()
            except Exception as e:
                traceback.print_exc()
                return ExceptionResponseJson("unable to validate credentials", e).make_response()
        else:
            return UnauthorizedResponseJson().make_response()
        return func(*args, **kwargs)
    return decorator
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号