-
Notifications
You must be signed in to change notification settings - Fork 7
/
app.py
91 lines (69 loc) · 2.73 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from datetime import timedelta
from flask import Flask
from flask_cors import CORS
from flask_jwt_extended import JWTManager
from flask_restx import Api
from database import db
app = Flask(__name__)
CORS(app)
api = Api(app)
ACCESS_EXPIRES = timedelta(hours=1)
app.config["PROPAGATE_EXCEPTIONS"] = True
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///app.db"
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
app.config["SECRET_KEY"] = "secret-key"
app.config["JWT_SECRET_KEY"] = "jwt-secret-key"
app.config["JWT_TOKEN_LOCATION"] = ["headers"]
app.config["JWT_ACCESS_TOKEN_EXPIRES"] = ACCESS_EXPIRES
jwt = JWTManager(app)
# db = SQLAlchemy(app)
db.init_app(app)
with app.app_context():
db.create_all()
from models import user_models # noqa: E402
from resources import (
method_resources,
problem_resources,
questionnaire_resources,
user_resources,
solution_archive_resources,
log_resources,
) # noqa: E402
# import views
@jwt.token_in_blocklist_loader
def check_if_token_revoked(jwt_header, jwt_payload):
jti = jwt_payload["jti"]
token = db.session.query(user_models.TokenBlocklist.id).filter_by(jti=jti).scalar()
return token is not None
# Add user endpoints
api.add_resource(user_resources.UserRegistration, "/registration")
api.add_resource(user_resources.UserLogin, "/login")
api.add_resource(user_resources.UserLogoutAccess, "/logout/access")
api.add_resource(user_resources.UserLogoutRefresh, "/logout/refresh")
api.add_resource(user_resources.TokenRefresh, "/token/refresh")
api.add_resource(user_resources.AllUsers, "/users")
api.add_resource(user_resources.SecretResource, "/secret")
# Add guest endpoints
api.add_resource(user_resources.GuestCreate, "/guest/create")
# Add problem endpoints
api.add_resource(problem_resources.ProblemCreation, "/problem/create")
api.add_resource(problem_resources.ProblemAccess, "/problem/access")
api.add_resource(problem_resources.ProblemAccessAll, "/problem/access/all")
# Add method endpoints
api.add_resource(method_resources.MethodCreate, "/method/create")
api.add_resource(method_resources.MethodControl, "/method/control")
# Add questionnaire endpoints
api.add_resource(
questionnaire_resources.QuestionnaireAfterSolutionProcess, "/questionnaire/after"
)
api.add_resource(
questionnaire_resources.QuestionnaireDuringSolutionProcess, "/questionnaire/during"
)
api.add_resource(
questionnaire_resources.QuestionnaireDuringSolutionProcessFirstIteration, "/questionnaire/during/first"
)
api.add_resource(questionnaire_resources.QuestionnaireDuringSolutionProcessAfterNew, "/questionnaire/during/new")
# Add archive endpoint
api.add_resource(solution_archive_resources.Archive, "/archive")
# Add log endpoint
api.add_resource(log_resources.LogEntryResource, "/log")