mirror of
https://github.com/simple-login/app.git
synced 2024-09-28 12:41:29 +02:00
fix api key counter not correctly incremented
This commit is contained in:
parent
3e5323c2dd
commit
ed22f5116f
@ -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)
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user