api_view.py 文件源码

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

项目:Feature-Request-Python-Flask 作者: jmcgrath207 项目源码 文件源码
def before_request(self,*args):
        """Verfies that the API is Vaild for the correct user
        and the IP address hasn't changed since log in"""

        signer = TimestampSigner(SECRET_KEY)
        api_key = request.headers['API_KEY']
        Client_id = request.headers['Client_ID']
        ip_address = request.remote_addr
        user = User.query.filter_by(Client_id=Client_id).first()
        if user == None:
            return make_response(jsonify({'Failure': 'Invaild User'}), 400)
        if api_key != user.api_key:
            return make_response(jsonify({'Failure': 'Incorrect API Key'}), 400)
        if ip_address != user.current_login_ip:
            return make_response(jsonify({'Failure': 'Incorrect IP for Client, Please Re-login in'}), 400)
        try:
            signer.unsign(api_key, max_age=86164)
        except:
            return make_response(jsonify({'Failure': 'Invaild API Key, please request new API Key'}), 400)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号