from flask import Flask
from flask_cors import CORS
from flask_restful import Api
from flask_sqlalchemy import SQLAlchemy
from flask_jwt_extended import JWTManager


app = Flask(__name__)
CORS(app)
api = Api(app)


app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///app.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SECRET_KEY'] = 'some-secret-string'
app.config['JWT_SECRET_KEY'] = 'jwt-secret-string'
app.config['JWT_BLACKLIST_ENABLED'] = True
app.config['JWT_BLACKLIST_TOKEN_CHECKS'] = ['access', 'refresh']


db = SQLAlchemy(app)
jwt = JWTManager(app)


@app.before_first_request
def create_tables():
    db.create_all()


import models, resources, views


api.add_resource(resources.UserRegistration, '/registration')
api.add_resource(resources.UserLogin, '/login')
api.add_resource(resources.UserLogoutAccess, '/logout/access')
api.add_resource(resources.UserLogoutRefresh, '/logout/refresh')
api.add_resource(resources.TokenRefresh, '/token/refresh')
api.add_resource(resources.AllUsers, '/users')
api.add_resource(resources.SecretResource, '/secret')


@jwt.token_in_blacklist_loader
def check_if_token_in_blacklist(decrypted_token):
    jti = decrypted_token['jti']
    return models.RevokedTokenModel.is_jti_blacklisted(jti)
[(8, 'flask.Flask', 'Flask', False, 'from flask import Flask\n'), (9, 'flask_cors.CORS', 'CORS', False, 'from flask_cors import CORS\n'), (10, 'flask_restful.Api', 'Api', False, 'from flask_restful import Api\n'), (21, 'flask_sqlalchemy.SQLAlchemy', 'SQLAlchemy', False, 'from flask_sqlalchemy import SQLAlchemy\n'), (22, 'flask_jwt_extended.JWTManager', 'JWTManager', False, 'from flask_jwt_extended import JWTManager\n'), (45, 'models.RevokedTokenModel.is_jti_blacklisted', 'models.RevokedTokenModel.is_jti_blacklisted', False, 'import models, resources, views\n')]