From ed22f5116f09378a165cc32233c77a2058fce2da Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Sat, 1 Aug 2020 10:14:59 +0200 Subject: [PATCH] fix api key counter not correctly incremented --- app/api/base.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/api/base.py b/app/api/base.py index 36d9bd50..6138464f 100644 --- a/app/api/base.py +++ b/app/api/base.py @@ -13,15 +13,16 @@ api_bp = Blueprint(name="api", import_name=__name__, url_prefix="/api") def require_api_auth(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) + api_code = request.headers.get("Authentication") + api_key = ApiKey.get_by(code=api_code) - if not api_key: + if not api_key: + # if user is authenticated, the request is authorized + if current_user.is_authenticated: + g.user = current_user + else: return jsonify(error="Wrong api key"), 401 - + else: # Update api key stats api_key.last_used = arrow.now() api_key.times += 1