support user already authenticated in verify_api_key

This commit is contained in:
Son NK 2020-04-24 14:06:42 +02:00 committed by Son NK
parent ae353dbb25
commit 78e94da08c

View file

@ -2,7 +2,7 @@ from functools import wraps
import arrow
from flask import Blueprint, request, jsonify, g
from flask_login import current_user
from app.extensions import db
from app.models import ApiKey
@ -12,6 +12,9 @@ api_bp = Blueprint(name="api", import_name=__name__, url_prefix="/api")
def verify_api_key(f):
@wraps(f)
def decorated(*args, **kwargs):
if current_user.is_authenticated:
g.user = current_user
else:
api_code = request.headers.get("Authentication")
api_key = ApiKey.get_by(code=api_code)