-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
56 lines (41 loc) · 1.91 KB
/
run.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
from datetime import timedelta
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_restful import Api
from flask_jwt_extended import JWTManager
from flask_migrate import Migrate
app = Flask(__name__)
api = Api(app=app)
app.config['SQLALCHEMY_DATABASE_URI'] = "mysql://iptech:CoffeeIpTech@127.0.0.1/coffee_cloud?charset=utf8&local_infile=1"
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SECRET_KEY'] = 'Coffee@IpTech'
app.config['PROPAGATE_EXCEPTIONS'] = True
db = SQLAlchemy(app, use_native_unicode='utf8')
migrate = Migrate(app=app, db=db)
@app.before_first_request
def create_tables():
db.create_all()
app.config['JWT_SECRET_KEY'] = 'jwt@IpTech'
jwt = JWTManager(app)
app.config['JWT_BLACKLIST_ENABLED'] = True
app.config['JWT_BLACKLIST_TOKEN_CHECKS'] = ['access', 'refresh']
app.config['JWT_ACCESS_TOKEN_EXPIRES'] = timedelta(minutes=15)
app.config['JWT_REFRESH_TOKEN_EXPIRES'] = timedelta(days=30)
@jwt.token_in_blacklist_loader
def check_if_token_in_blacklist(decrypted_token):
jti = decrypted_token['jti']
return models.RevokedTokenModel.is_jti_blacklisted(jti)
import models
import resources
api.add_resource(resources.UserRegistration, '/user/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.UserResetPassword, '/user/reset_password')
api.add_resource(resources.TokenRefresh, '/token/refresh')
api.add_resource(resources.UserProfileRoute, '/user/', '/user/<int:user_id>', endpoint='user_id')
api.add_resource(resources.UserProfile, '/user_profile')
api.add_resource(resources.MenuResource, '/menu')
api.add_resource(resources.OrderResourceRoute, '/order/<int:order_id>', endpoint='order_id')
api.add_resource(resources.OrderResource, '/order')
api.add_resource(resources.SerialNumberResource, '/serial_number')