Merge pull request #246 from simple-login/fix-ai-key

fix api key counter not correctly incremented
This commit is contained in:
Son Nguyen Kim 2020-08-01 10:15:25 +02:00 committed by GitHub
commit c8a4c53870
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 7 deletions

View File

@ -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