-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
87 lines (71 loc) · 2.53 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
import ssl
from flask import Flask, jsonify
from flask_restful import Api
from flask_jwt_extended import JWTManager
from flask_migrate import Migrate
from marshmallow import ValidationError
from flask_uploads import configure_uploads, patch_request_class
from starlette import status
from dotenv import load_dotenv
load_dotenv(".env.dev", verbose=True)
from blacklist import BLACKLIST
from database.db import db
from serializers.ma import ma
from oauth.oa import oauth
from resources.user import (
UserRegister,
UserLogin,
User,
TokenRefresh,
UserLogout,
SetPassword,
)
from resources.item import Item, ItemList
from resources.store import Store, StoreList
# from resources.confirmation import Confirmation, ConfirmationByUser
from resources.image import ImageUpload, Image, AvatarUpload, Avatar
from resources.github_login import GithubLogin, GithubAuthorize
from libs.image_helper import IMAGE_SET
app = Flask(__name__)
app.config.from_object("config.default_config")
app.config.from_envvar("APPLICATION_SETTINGS", silent=True)
patch_request_class(app, 10 * 1024 * 1024)
configure_uploads(app, IMAGE_SET)
db.init_app(app)
api = Api(app)
jwt = JWTManager(app)
migrate = Migrate(app, db)
@app.before_first_request
def create_tables():
db.create_all()
@app.errorhandler(ValidationError)
def handle_marshmallow(err):
return jsonify(err.messages), status.HTTP_400_BAD_REQUEST
@jwt.token_in_blocklist_loader
def check_if_token_in_blacklist(decrypted_token):
return decrypted_token["jti"] in BLACKLIST
api.add_resource(Store, "/store/<string:name>")
api.add_resource(StoreList, "/stores")
api.add_resource(Item, "/item/<string:name>")
api.add_resource(ItemList, "/items")
api.add_resource(UserRegister, "/register")
api.add_resource(User, "/user/<int:user_id>")
api.add_resource(UserLogin, "/login")
api.add_resource(TokenRefresh, "/refresh")
api.add_resource(UserLogout, "/logout")
# api.add_resource(Confirmation, "/user_confirmation/<string:confirmation_id>")
# api.add_resource(ConfirmationByUser, "/confirmation/user/<int:user_id>")
api.add_resource(ImageUpload, "/upload/image")
api.add_resource(Image, "/image/<string:filename>")
api.add_resource(AvatarUpload, "/upload/avatar")
api.add_resource(Avatar, "/avatar/<int:user_id>")
api.add_resource(GithubLogin, "/login/github")
api.add_resource(
GithubAuthorize, "/login/github/authorized", endpoint="github.authorize"
)
api.add_resource(SetPassword, "/user/password")
if __name__ == "__main__":
db.init_app(app)
ma.init_app(app)
oauth.init_app(app)
app.run(port=5000)