Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a non-public user to get their event context #422

Merged
merged 3 commits into from
Dec 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion omeroweb/webgateway/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3344,6 +3344,7 @@ def post(self, request, api_version=None):
"""
error = None
form = self.form_class(request.POST.copy())
userip = get_client_ip(request)
if form.is_valid():
username = form.cleaned_data["username"]
password = form.cleaned_data["password"]
Expand All @@ -3363,7 +3364,7 @@ def post(self, request, api_version=None):
and compatible
):
conn = connector.create_connection(
self.useragent, username, password, userip=get_client_ip(request)
self.useragent, username, password, userip=userip
)
if conn is not None:
try:
Expand Down Expand Up @@ -3396,6 +3397,30 @@ def post(self, request, api_version=None):
)
else:
error = settings.LOGIN_INCORRECT_CREDENTIALS_TEXT
elif "connector" in request.session and (
len(form.data) == 0
or ("csrfmiddlewaretoken" in form.data and len(form.data) == 1)
):
# If we appear to already be logged in and the form we've been
# provided is empty repeat the "logged in" behaviour so a user
# can get their event context. A form with length 1 is considered
# empty as a valid CSRF token is required to even get into this
# method. The CSRF token may also have been provided via HTTP
# header in which case the form length will be 0.
connector = request.session["connector"]
# Do not allow retrieval of the event context of the public user
if not connector.is_public:
conn = connector.join_connection(self.useragent, userip)
# Connection is None if it could not be successfully joined
# and any omero.client objects will have had close() called
# on them.
if conn is not None:
try:
return self.handle_logged_in(request, conn, connector)
except Exception:
pass
finally:
conn.close(hard=False)
return self.handle_not_logged_in(request, error, form)


Expand Down