Skip to content

Commit

Permalink
🧹 reformatted
Browse files Browse the repository at this point in the history
  • Loading branch information
lint-action committed Feb 19, 2024
1 parent 6376802 commit 9ac32bf
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions server/blueprints/auth/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@


def audit_login(emoji: str, ip: str, username: str, result: str):
requests.post(current_app.config.DISCORD_LOGIN_NOTIFICATIONS, json={
"content": f"[{emoji}] [{username}] [{ip}] {result}"
})
requests.post(
current_app.config.DISCORD_LOGIN_NOTIFICATIONS,
json={"content": f"[{emoji}] [{username}] [{ip}] {result}"},
)


def get_ip():
if request.environ.get('HTTP_X_FORWARDED_FOR') is None:
return request.environ['REMOTE_ADDR']
if request.environ.get("HTTP_X_FORWARDED_FOR") is None:
return request.environ["REMOTE_ADDR"]
else:
return request.environ['HTTP_X_FORWARDED_FOR'] # if behind a proxy
return request.environ["HTTP_X_FORWARDED_FOR"] # if behind a proxy


def basic_http_auth_required(f):
Expand Down Expand Up @@ -56,7 +57,9 @@ def wrapper(*args, **kwargs):
audit_login("⚠️", get_ip(), "?", "Failed (missing totp or auth)")
abort(401)
if not verify_password(auth.username, auth.password): # wrong first factor
audit_login("⚠️", get_ip(), auth.username, "Failed (invalid password or username)")
audit_login(
"⚠️", get_ip(), auth.username, "Failed (invalid password or username)"
)
abort(401)
if not verify_totp(totp, g.user): # wrong second factor
audit_login("⚠️", get_ip(), auth.username, "Failed (invalid totp)")
Expand Down

0 comments on commit 9ac32bf

Please sign in to comment.