2024-12-27 23:23:21 +02:00
|
|
|
from flask import Flask, request, jsonify
|
2024-12-29 18:21:37 +02:00
|
|
|
from flask_jwt_extended import create_access_token, get_jwt_identity, jwt_required, JWTManager
|
2024-09-24 20:25:06 +03:00
|
|
|
import time
|
2024-10-28 20:10:04 +02:00
|
|
|
import json
|
2024-12-27 23:23:21 +02:00
|
|
|
import uuid
|
2024-12-29 18:21:37 +02:00
|
|
|
import datetime
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
from hashlib import sha256
|
2024-09-24 20:25:06 +03:00
|
|
|
|
2024-12-27 21:51:19 +02:00
|
|
|
from marshmallow import Schema, fields
|
|
|
|
from flask_sqlalchemy import SQLAlchemy
|
|
|
|
|
2024-09-24 20:25:06 +03:00
|
|
|
app = Flask(__name__)
|
2024-12-27 21:51:19 +02:00
|
|
|
app.config.from_pyfile('config.py', silent=True)
|
2024-12-29 18:21:37 +02:00
|
|
|
app.config["JWT_SECRET_KEY"] = os.getenv("JWT_SECRET_KEY")
|
|
|
|
|
|
|
|
#print(app.config["JWT_SECRET_KEY"], file = sys.stderr)
|
2024-12-27 21:51:19 +02:00
|
|
|
|
|
|
|
db = SQLAlchemy(app)
|
2024-12-29 18:21:37 +02:00
|
|
|
jwt = JWTManager(app)
|
2024-12-27 21:51:19 +02:00
|
|
|
|
|
|
|
class UserModel(db.Model):
|
|
|
|
__tablename__ = "user"
|
|
|
|
uuid = db.Column(db.String(32), unique=True, primary_key=True, nullable=False)
|
|
|
|
name = db.Column(db.String(64), nullable=False)
|
2024-12-29 18:21:37 +02:00
|
|
|
password = db.Column(db.String(64), nullable=False)
|
2024-12-28 18:50:46 +02:00
|
|
|
bal_uuid = db.Column(db.String(32), db.ForeignKey('balance.uuid'))
|
2024-12-27 21:51:19 +02:00
|
|
|
|
|
|
|
class CategoryModel(db.Model):
|
|
|
|
__tablename__ = "category"
|
|
|
|
uuid = db.Column(db.String(32), unique=True, primary_key=True, nullable=False)
|
|
|
|
name = db.Column(db.String(64), nullable=False)
|
|
|
|
|
2024-12-27 23:23:21 +02:00
|
|
|
class RecordModel(db.Model):
|
2024-12-27 21:51:19 +02:00
|
|
|
__tablename__ = "record"
|
|
|
|
uuid = db.Column(db.String(32), primary_key=True, nullable=False)
|
|
|
|
user_uuid = db.Column(db.String(32), db.ForeignKey('user.uuid'))
|
|
|
|
cat_uuid = db.Column(db.String(32), db.ForeignKey('category.uuid'))
|
|
|
|
date = db.Column(db.Date)
|
|
|
|
amount = db.Column(db.Integer)
|
|
|
|
|
2024-12-28 18:50:46 +02:00
|
|
|
class BalanceModel(db.Model):
|
|
|
|
__tablename__ = "balance"
|
|
|
|
uuid = db.Column(db.String(32), primary_key=True, nullable=False)
|
|
|
|
value = db.Column(db.Integer, nullable=False)
|
|
|
|
|
|
|
|
|
2024-12-27 21:51:19 +02:00
|
|
|
class UserSchema(Schema):
|
|
|
|
uuid = fields.Str()
|
|
|
|
name = fields.Str()
|
2024-12-29 18:21:37 +02:00
|
|
|
password = fields.Str()
|
2024-12-28 18:50:46 +02:00
|
|
|
bal_uuid = fields.Str()
|
2024-12-27 21:51:19 +02:00
|
|
|
|
|
|
|
class CategorySchema(Schema):
|
|
|
|
uuid = fields.Str()
|
|
|
|
name = fields.Str()
|
|
|
|
|
|
|
|
class RecordSchema(Schema):
|
|
|
|
uuid = fields.Str()
|
|
|
|
user_uuid = fields.Str()
|
|
|
|
cat_uuid = fields.Str()
|
2024-12-29 18:21:37 +02:00
|
|
|
date = fields.Date('iso')
|
2024-12-27 21:51:19 +02:00
|
|
|
amount = fields.Integer()
|
|
|
|
|
2024-12-28 18:50:46 +02:00
|
|
|
class BalanceSchema(Schema):
|
|
|
|
uuid = fields.Str()
|
|
|
|
value = fields.Integer()
|
|
|
|
|
2024-12-27 23:23:21 +02:00
|
|
|
user_schema = UserSchema()
|
|
|
|
users_schema = UserSchema(many = True)
|
|
|
|
|
|
|
|
category_schema = CategorySchema()
|
|
|
|
categories_schema = CategorySchema(many = True)
|
|
|
|
|
|
|
|
record_schema = RecordSchema()
|
|
|
|
records_schema = RecordSchema(many = True)
|
|
|
|
|
2024-12-28 18:50:46 +02:00
|
|
|
balance_schema = BalanceSchema()
|
|
|
|
|
2024-12-27 21:51:19 +02:00
|
|
|
# "migration"
|
|
|
|
with app.app_context():
|
|
|
|
db.create_all()
|
2024-09-24 20:25:06 +03:00
|
|
|
|
|
|
|
@app.route("/healthcheck")
|
|
|
|
def ep_healthcheck():
|
|
|
|
return {
|
|
|
|
"date": time.strftime('%Y.%m.%d %H:%M:%S'),
|
|
|
|
"status": "OK"
|
|
|
|
}
|
2024-10-28 17:19:47 +02:00
|
|
|
|
2024-10-28 17:27:34 +02:00
|
|
|
@app.route("/reset_users_because_postman_is_dumb_like_that")
|
|
|
|
def ep_reset():
|
2024-12-28 15:10:29 +02:00
|
|
|
db.session.query(RecordModel).delete()
|
|
|
|
db.session.query(CategoryModel).delete()
|
2024-12-28 12:49:54 +02:00
|
|
|
db.session.query(UserModel).delete()
|
2024-12-28 18:50:46 +02:00
|
|
|
db.session.query(BalanceModel).delete()
|
2024-12-28 12:49:54 +02:00
|
|
|
db.session.commit()
|
|
|
|
return {}, 200
|
2024-10-28 17:27:34 +02:00
|
|
|
|
2024-10-28 17:19:47 +02:00
|
|
|
@app.route("/users", methods = ["GET"])
|
2024-12-29 18:21:37 +02:00
|
|
|
@jwt_required()
|
2024-10-28 17:19:47 +02:00
|
|
|
def ep_users_get():
|
2024-12-27 23:23:21 +02:00
|
|
|
result = db.session.query(UserModel).all()
|
|
|
|
return users_schema.dumps(result)
|
2024-10-28 17:19:47 +02:00
|
|
|
|
|
|
|
@app.route("/user", methods = ["POST"])
|
|
|
|
def ep_user_post():
|
2024-12-29 18:21:37 +02:00
|
|
|
name = request.json.get('name', None)
|
|
|
|
password = request.json.get('password', None)
|
2024-10-28 17:19:47 +02:00
|
|
|
|
2024-12-29 18:21:37 +02:00
|
|
|
pass_hashed = sha256(password.encode("UTF-8")).digest().hex()
|
2024-10-28 17:19:47 +02:00
|
|
|
|
2024-12-28 18:50:46 +02:00
|
|
|
b = BalanceModel(uuid=uuid.uuid4().hex, value=0)
|
2024-12-29 18:21:37 +02:00
|
|
|
|
|
|
|
u_uuid = uuid.uuid4().hex
|
|
|
|
bal_uuid = b.uuid
|
2024-12-27 23:23:21 +02:00
|
|
|
|
|
|
|
try:
|
2024-12-29 18:21:37 +02:00
|
|
|
_ = user_schema.load({'uuid': u_uuid, 'name': name,
|
|
|
|
'password': pass_hashed, 'bal_uuid': bal_uuid})
|
|
|
|
except Exception as e:
|
|
|
|
print(e, file=sys.stderr)
|
2024-12-27 23:23:21 +02:00
|
|
|
return {}, 403
|
|
|
|
|
2024-12-29 18:21:37 +02:00
|
|
|
u = UserModel(uuid=u_uuid, name=name,
|
|
|
|
password=pass_hashed, bal_uuid=bal_uuid)
|
|
|
|
|
|
|
|
at = create_access_token(identity = json.dumps({'uuid': u.uuid, 'bal_uuid': u.bal_uuid}))
|
2024-12-27 23:23:21 +02:00
|
|
|
|
|
|
|
try:
|
2024-12-28 18:50:46 +02:00
|
|
|
db.session.add(b)
|
2024-12-27 23:23:21 +02:00
|
|
|
db.session.add(u)
|
|
|
|
db.session.commit()
|
|
|
|
except Exception as e:
|
|
|
|
db.session.rollback()
|
|
|
|
return {}, 403
|
|
|
|
|
2024-12-29 18:21:37 +02:00
|
|
|
return jsonify(access_token = at, uuid = u.uuid), 200
|
2024-12-27 23:23:21 +02:00
|
|
|
|
2024-12-29 18:21:37 +02:00
|
|
|
@app.route("/user", methods = ["GET"])
|
|
|
|
def ep_user_get():
|
|
|
|
name = request.json.get('user', None)
|
|
|
|
password = request.json.get('password', None)
|
|
|
|
pass_hashed = sha256(password.encode("UTF-8")).digest().hex()
|
2024-10-28 17:19:47 +02:00
|
|
|
|
2024-12-29 18:21:37 +02:00
|
|
|
u = db.session.query(UserModel).filter(UserModel.name == name).one_or_none()
|
|
|
|
|
|
|
|
if not u:
|
2024-12-28 12:49:54 +02:00
|
|
|
return {}, 404
|
|
|
|
|
2024-12-29 18:21:37 +02:00
|
|
|
if u.password != pass_hashed:
|
|
|
|
return {"message": "Wrong password."}, 401
|
|
|
|
|
|
|
|
at = create_access_token(identity = json.dumps({'uuid': u.uuid, 'bal_uuid': u.bal_uuid}))
|
|
|
|
|
|
|
|
return jsonify(access_token = at, uuid = u.uuid), 200
|
|
|
|
|
|
|
|
@app.route("/user", methods = ["DELETE"])
|
|
|
|
@jwt_required()
|
|
|
|
def ep_user_delete():
|
|
|
|
current_user = json.loads(get_jwt_identity())
|
|
|
|
|
2024-12-28 18:50:46 +02:00
|
|
|
try:
|
2024-12-29 18:21:37 +02:00
|
|
|
db.session.query(UserModel).filter(UserModel.uuid == current_user['uuid']).delete()
|
|
|
|
db.session.query(BalanceModel).filter(BalanceModel.uuid == current_user['bal_uuid']).delete()
|
2024-12-28 18:50:46 +02:00
|
|
|
db.session.commit()
|
|
|
|
except Exception as e:
|
|
|
|
db.session.rollback()
|
|
|
|
return {}, 403
|
2024-12-28 12:49:54 +02:00
|
|
|
|
2024-12-29 18:21:37 +02:00
|
|
|
return {"message": "Success."}, 200
|
2024-10-28 18:18:28 +02:00
|
|
|
|
|
|
|
@app.route("/category", methods = ["GET"])
|
2024-12-29 18:21:37 +02:00
|
|
|
@jwt_required()
|
2024-10-28 18:18:28 +02:00
|
|
|
def ep_category_get():
|
|
|
|
body = request.json
|
|
|
|
|
|
|
|
if 'uuid' in body:
|
2024-12-28 15:10:29 +02:00
|
|
|
result = db.session.query(CategoryModel).filter(CategoryModel.uuid == body['uuid']).all()
|
2024-10-28 18:18:28 +02:00
|
|
|
|
2024-12-28 15:10:29 +02:00
|
|
|
if len(result) == 1:
|
|
|
|
return user_schema.dumps(result[0]), 200
|
2024-10-28 18:18:28 +02:00
|
|
|
else:
|
2024-12-28 15:10:29 +02:00
|
|
|
return {}, 404
|
2024-10-28 18:18:28 +02:00
|
|
|
else:
|
|
|
|
return {}, 403
|
|
|
|
|
|
|
|
@app.route("/category", methods = ["POST"])
|
2024-12-29 18:21:37 +02:00
|
|
|
@jwt_required()
|
2024-10-28 18:18:28 +02:00
|
|
|
def ep_category_post():
|
|
|
|
body = request.json
|
|
|
|
|
2024-12-28 15:10:29 +02:00
|
|
|
if not body:
|
|
|
|
return {}, 403
|
2024-10-28 18:18:28 +02:00
|
|
|
|
2024-12-28 15:10:29 +02:00
|
|
|
if 'uuid' in body:
|
2024-10-28 18:18:28 +02:00
|
|
|
return {}, 403
|
|
|
|
|
2024-12-28 15:10:29 +02:00
|
|
|
body.update({'uuid': uuid.uuid4().hex})
|
|
|
|
|
|
|
|
try:
|
|
|
|
_ = category_schema.load(body)
|
|
|
|
except ValidationError as e:
|
|
|
|
return {}, 403
|
|
|
|
|
|
|
|
c = CategoryModel(**body)
|
|
|
|
|
|
|
|
try:
|
|
|
|
db.session.add(c)
|
|
|
|
db.session.commit()
|
|
|
|
except Exception as e:
|
|
|
|
db.session.rollback()
|
|
|
|
return {}, 403
|
|
|
|
|
|
|
|
return jsonify(category_schema.load(body)), 200
|
|
|
|
|
2024-10-28 18:18:28 +02:00
|
|
|
@app.route("/category", methods = ["DELETE"])
|
2024-12-29 18:21:37 +02:00
|
|
|
@jwt_required()
|
2024-10-28 18:18:28 +02:00
|
|
|
def ep_category_delete():
|
|
|
|
body = request.json
|
|
|
|
|
2024-12-28 15:10:29 +02:00
|
|
|
if 'uuid' not in body:
|
|
|
|
return {}, 403
|
2024-10-28 18:18:28 +02:00
|
|
|
|
2024-12-28 15:10:29 +02:00
|
|
|
cat_id = body['uuid']
|
|
|
|
|
|
|
|
try:
|
|
|
|
result = db.session.query(CategoryModel).filter(CategoryModel.uuid == cat_id).all()
|
|
|
|
except Exception as e:
|
2024-10-28 18:18:28 +02:00
|
|
|
return {}, 403
|
2024-10-28 20:10:04 +02:00
|
|
|
|
2024-12-28 15:10:29 +02:00
|
|
|
if len(result) == 0:
|
|
|
|
return {}, 404
|
|
|
|
|
2024-12-28 18:50:46 +02:00
|
|
|
try:
|
|
|
|
db.session.query(CategoryModel).filter(CategoryModel.uuid == cat_id).delete()
|
|
|
|
db.session.commit()
|
|
|
|
except Exception as e:
|
|
|
|
return {}, 403
|
2024-12-28 15:10:29 +02:00
|
|
|
|
|
|
|
return category_schema.dumps(result[0]), 200
|
|
|
|
|
2024-10-28 20:10:04 +02:00
|
|
|
@app.route("/record/<record_id>", methods = ["GET"])
|
2024-12-29 18:21:37 +02:00
|
|
|
@jwt_required()
|
2024-10-28 20:10:04 +02:00
|
|
|
def ep_record_get(record_id):
|
2024-12-29 18:21:37 +02:00
|
|
|
current_user = json.loads(get_jwt_identity())
|
|
|
|
result = db.session.query(RecordModel).filter(RecordModel.uuid == record_id).one_or_none()
|
2024-10-28 20:10:04 +02:00
|
|
|
|
2024-12-29 18:21:37 +02:00
|
|
|
if result and result.user_uuid == current_user['uuid']:
|
|
|
|
return user_schema.dumps(result), 200
|
2024-10-28 20:10:04 +02:00
|
|
|
else:
|
2024-12-29 18:21:37 +02:00
|
|
|
return {}, 403
|
2024-10-28 20:10:04 +02:00
|
|
|
|
|
|
|
@app.route("/record", methods = ["GET"])
|
2024-12-29 18:21:37 +02:00
|
|
|
@jwt_required()
|
2024-10-28 20:10:04 +02:00
|
|
|
def ep_record_get_filtered():
|
2024-12-28 15:10:29 +02:00
|
|
|
r = db.session.query(RecordModel)
|
|
|
|
|
|
|
|
filtered = False
|
2024-10-28 20:10:04 +02:00
|
|
|
|
|
|
|
if 'user_id' in request.json:
|
2024-12-28 15:10:29 +02:00
|
|
|
r = r.filter(RecordModel.user_uuid == request.json['user_id'])
|
|
|
|
filtered = True
|
|
|
|
elif 'user_uuid' in request.json:
|
|
|
|
r = r.filter(RecordModel.user_uuid == request.json['user_uuid'])
|
|
|
|
filtered = True
|
2024-10-28 20:10:04 +02:00
|
|
|
|
|
|
|
if 'cat_id' in request.json:
|
2024-12-28 15:10:29 +02:00
|
|
|
r = r.filter(RecordModel.cat_uuid == request.json['cat_id'])
|
|
|
|
filtered = True
|
|
|
|
if 'cat_uuid' in request.json:
|
|
|
|
r = r.filter(RecordModel.cat_uuid == request.json['cat_uuid'])
|
|
|
|
filtered = True
|
2024-10-28 20:10:04 +02:00
|
|
|
|
2024-12-28 15:10:29 +02:00
|
|
|
if filtered:
|
|
|
|
return records_schema.dumps(r.all())
|
|
|
|
else:
|
|
|
|
return [], 403
|
2024-10-28 20:10:04 +02:00
|
|
|
|
|
|
|
@app.route("/record/<record_id>", methods = ["DELETE"])
|
2024-12-29 18:21:37 +02:00
|
|
|
@jwt_required()
|
2024-10-28 20:10:04 +02:00
|
|
|
def ep_record_del(record_id):
|
2024-12-29 18:21:37 +02:00
|
|
|
current_user = json.loads(get_jwt_identity())
|
|
|
|
|
2024-12-28 15:10:29 +02:00
|
|
|
try:
|
2024-12-29 18:21:37 +02:00
|
|
|
result = db.session.query(RecordModel).filter(RecordModel.uuid == record_id).one_or_none()
|
2024-12-28 15:10:29 +02:00
|
|
|
except Exception as e:
|
|
|
|
return {}, 403
|
2024-10-28 20:10:04 +02:00
|
|
|
|
2024-12-29 18:21:37 +02:00
|
|
|
if result and result.user_uuid == current_user['uuid']:
|
|
|
|
db.session.query(RecordModel).filter(RecordModel.uuid == record_id).delete()
|
|
|
|
db.session.commit()
|
|
|
|
else:
|
|
|
|
return {}, 401
|
2024-12-28 15:10:29 +02:00
|
|
|
|
2024-12-29 18:21:37 +02:00
|
|
|
return record_schema.dumps(result), 200
|
2024-10-28 20:10:04 +02:00
|
|
|
|
|
|
|
@app.route("/record", methods = ["POST"])
|
2024-12-29 18:21:37 +02:00
|
|
|
@jwt_required()
|
2024-10-28 20:10:04 +02:00
|
|
|
def ep_record_post():
|
2024-12-29 18:21:37 +02:00
|
|
|
current_user = json.loads(get_jwt_identity())
|
2024-10-28 20:10:04 +02:00
|
|
|
|
2024-12-29 18:21:37 +02:00
|
|
|
amount = request.json.get('amount', None)
|
|
|
|
category = request.json.get('category', None)
|
2024-10-28 20:10:04 +02:00
|
|
|
|
2024-12-29 18:21:37 +02:00
|
|
|
if not all([amount, category]):
|
2024-12-28 15:10:29 +02:00
|
|
|
return {}, 403
|
|
|
|
|
2024-12-29 18:21:37 +02:00
|
|
|
u_uuid = uuid.uuid4().hex
|
2024-10-28 20:10:04 +02:00
|
|
|
|
2024-12-29 18:21:37 +02:00
|
|
|
r_time = time.strftime("%Y-%m-%d")
|
2024-10-28 20:10:04 +02:00
|
|
|
|
2024-12-28 15:10:29 +02:00
|
|
|
try:
|
2024-12-29 18:21:37 +02:00
|
|
|
#_ = record_schema.load(amount=amount, cat_uuid=category, uuid=u_uuid,
|
|
|
|
# user_uuid=current_user['uuid'], date=datetime.datetime.now())
|
|
|
|
_ = record_schema.load({'amount': amount, "cat_uuid": category, "uuid": u_uuid,
|
|
|
|
'user_uuid': current_user['uuid'], 'date': r_time})
|
2024-12-28 15:10:29 +02:00
|
|
|
except Exception as e:
|
2024-12-29 18:21:37 +02:00
|
|
|
print(e, file = sys.stderr)
|
|
|
|
return {}, 400
|
2024-12-28 15:10:29 +02:00
|
|
|
|
2024-12-29 18:21:37 +02:00
|
|
|
r = RecordModel(amount=amount, cat_uuid=category, uuid=u_uuid, user_uuid=current_user['uuid'], date=r_time)
|
2024-12-28 18:50:46 +02:00
|
|
|
|
|
|
|
v = db.session \
|
|
|
|
.query(BalanceModel) \
|
2024-12-29 18:21:37 +02:00
|
|
|
.filter(BalanceModel.uuid == current_user['bal_uuid']) \
|
|
|
|
.one_or_none() \
|
2024-12-28 18:50:46 +02:00
|
|
|
.value
|
|
|
|
|
2024-12-29 18:21:37 +02:00
|
|
|
BalanceModel \
|
|
|
|
.metadata.tables.get("balance") \
|
|
|
|
.update() \
|
|
|
|
.where(BalanceModel.metadata.tables.get("balance").c.uuid == current_user['bal_uuid']) \
|
|
|
|
.values(value = v - amount)
|
2024-12-28 18:50:46 +02:00
|
|
|
|
2024-12-28 15:10:29 +02:00
|
|
|
try:
|
|
|
|
db.session.add(r)
|
|
|
|
db.session.commit()
|
|
|
|
except Exception as e:
|
2024-12-29 18:21:37 +02:00
|
|
|
print(e, file = sys.stderr)
|
2024-12-28 15:10:29 +02:00
|
|
|
db.session.rollback()
|
|
|
|
return {}, 403
|
|
|
|
|
2024-12-29 18:21:37 +02:00
|
|
|
return {'uuid': r.uuid}, 200
|
2024-12-28 18:50:46 +02:00
|
|
|
|
|
|
|
@app.route("/balance_up", methods = ["POST"])
|
2024-12-29 18:21:37 +02:00
|
|
|
@jwt_required()
|
2024-12-28 18:50:46 +02:00
|
|
|
def ep_balance_up():
|
2024-12-29 18:21:37 +02:00
|
|
|
current_user = json.loads(get_jwt_identity())
|
2024-12-28 18:50:46 +02:00
|
|
|
|
2024-12-29 18:21:37 +02:00
|
|
|
amount = request.json.get('amount', None)
|
2024-12-28 18:50:46 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
v = db.session \
|
|
|
|
.query(BalanceModel) \
|
2024-12-29 18:21:37 +02:00
|
|
|
.filter(BalanceModel.uuid == current_user['bal_uuid']) \
|
|
|
|
.one_or_none() \
|
2024-12-28 18:50:46 +02:00
|
|
|
.value
|
|
|
|
|
2024-12-29 18:21:37 +02:00
|
|
|
BalanceModel.metadata.tables.get("balance").update().where(BalanceModel.metadata.tables.get("balance").c.uuid == current_user['bal_uuid']).values(value = v + amount)
|
2024-12-28 18:50:46 +02:00
|
|
|
except Exception as e:
|
2024-12-29 18:21:37 +02:00
|
|
|
print(e, file = sys.stderr)
|
|
|
|
return {}, 407
|
2024-12-28 18:50:46 +02:00
|
|
|
|
|
|
|
return {}, 200
|
|
|
|
|
|
|
|
@app.route("/balance", methods = ["GET"])
|
2024-12-29 18:21:37 +02:00
|
|
|
@jwt_required()
|
2024-12-28 18:50:46 +02:00
|
|
|
def ep_balance_get():
|
2024-12-29 18:21:37 +02:00
|
|
|
current_user = json.loads(get_jwt_identity())
|
|
|
|
result = db.session.query(BalanceModel).filter(BalanceModel.uuid == current_user['bal_uuid']).one_or_none()
|
|
|
|
|
|
|
|
return balance_schema.dumps(result), 200
|
|
|
|
|
|
|
|
@jwt.expired_token_loader
|
|
|
|
def expired_token_callback(jwt_header, jwt_payload):
|
|
|
|
return (
|
|
|
|
jsonify({"message": "The token has expired.", "error": "token_expired"}),
|
|
|
|
401,
|
|
|
|
)
|
|
|
|
|
|
|
|
@jwt.invalid_token_loader
|
|
|
|
def invalid_token_callback(error):
|
|
|
|
return (
|
|
|
|
jsonify(
|
|
|
|
{"message": "Signature verification failed.", "error": "invalid_token"}
|
|
|
|
),
|
|
|
|
401,
|
|
|
|
)
|
|
|
|
|
|
|
|
@jwt.unauthorized_loader
|
|
|
|
def missing_token_callback(error):
|
|
|
|
return (
|
|
|
|
jsonify(
|
|
|
|
{
|
|
|
|
"description": "Request does not contain an access token.",
|
|
|
|
"error": "authorization_required",
|
|
|
|
}
|
|
|
|
),
|
|
|
|
401,
|
|
|
|
)
|