Skip to content

Commit

Permalink
Fix issue #25
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelzdrav committed Aug 14, 2023
1 parent d5f7c13 commit b87931f
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions web/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,21 @@
def get_current_tenant_id():
return session.get("tenant_id")


def get_user_ip(req):
if 'HTTP_X_FORWARDED_FOR' in req.environ is None:
if "HTTP_X_FORWARDED_FOR" in req.environ is None:
return req.environ.get["REMOTE_ADDR"]
else:
return req.environ.get('HTTP_X_FORWARDED_FOR', request.remote_addr) # if behind a proxy
return req.environ.get(
"HTTP_X_FORWARDED_FOR", request.remote_addr
) # if behind a proxy


# Check expired tasks on user login
def check_for_expired_tasks():
tz = session.get("timezone")

if tz is not None:

today = datetime.now(timezone("UTC")).date()

tenants = db.session.query(Tenant).all()
Expand All @@ -47,7 +50,7 @@ def check_for_expired_tasks():

for task in tasks:
if (
task.status != "OVERDUE"
(task.status != "OVERDUE" and task.status != "DONE")
and task.due_date
and task.due_date.date() <= today
):
Expand Down Expand Up @@ -166,12 +169,12 @@ def login():

current_app.logger.info(
"Log In attempt - %s, %s, %s, %s",
request.headers.get('X-Forwarded-For'),
request.headers.get('X-Real-IP'),
request.headers.get('X-Client-IP'),
get_user_ip(request)
request.headers.get("X-Forwarded-For"),
request.headers.get("X-Real-IP"),
request.headers.get("X-Client-IP"),
get_user_ip(request),
)

if error is None:
tenancy = Tenant.query.filter_by(id=user.tenant_id).first()
session.clear()
Expand Down Expand Up @@ -234,6 +237,7 @@ def logout():
else:
return redirect(url_for("auth.login"))


def login_required(view):
@functools.wraps(view)
def wrapped_view(**kwargs):
Expand Down

0 comments on commit b87931f

Please sign in to comment.