-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
44 lines (32 loc) · 1.2 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from flask import Flask, jsonify
from flask_restful import Api
from resources.philosopher import Philosophers, Philosopher
from resources.user import User, UserRegister, UserLogin, UserLogout
from flask_jwt_extended import JWTManager
from blacklist import BLACKLIST
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///philosoup.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['JWT_SECRET_KEY'] = 'your_secret_key_here'
app.config['JWT_BLACKLIST_ENABLED'] = True
api = Api(app)
jwt = JWTManager(app)
@app.before_first_request
def create_database():
database.create_all()
@jwt.token_in_blacklist_loader
def verify_blacklist(token):
return token['jti'] in BLACKLIST
@jwt.revoked_token_loader
def invalid_token():
return jsonify({'message': 'You have been logged out'}), 401
api.add_resource(Philosophers, '/philosophers')
api.add_resource(Philosopher, '/philosophers/<string:id>')
api.add_resource(User, '/user/<int:user_id>')
api.add_resource(UserRegister, '/signup')
api.add_resource(UserLogin, '/login')
api.add_resource(UserLogout, '/logout')
if __name__ == '__main__':
from sql_alchemy import database
database.init_app(app)
app.run(debug=True)