Skip to content

Commit

Permalink
Support #339
Browse files Browse the repository at this point in the history
  • Loading branch information
nutjob4life committed Feb 2, 2024
1 parent 83eec6d commit ceaaa36
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 18 deletions.
38 changes: 38 additions & 0 deletions src/edrn.auth/src/edrn/auth/templates/edrn.auth/portal-login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{% extends 'base.html' %}
{% load edrn_auth_tags i18n edrnsite_content_tags %}
{% block content %}
<div class='row m-3 mb-4'>
<div class='col'>
<h1>Log In</h1>

{% if form.errors %}
<p class='text-warning'><strong>{% trans "Your username and password didn't match. Please try again." %}</strong></p>
{% endif %}

{% if next and request.user.is_authenticated %}
<p class='text-danger'><strong>{% trans "Your account doesn't have access to this page. To proceed, please log in with an account that has access." %}</strong></p>
{% endif %}

<div class='row mb-3'>
<div class='col-lg-12'>
<p>
Logging in tothe EDRN public portal may afford you access to
additional biomarker and scientific data. Also, if you have the
appropriate permissions, you can edit the pages, images, and files
on this site. Use your EDRN username and password in the below form
to log in.
</p>
<form method="post" action="{% url 'wagtailcore_login' %}" class='mb-4'>
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="{% trans "Log in" %}" class="button" />
<input type="hidden" name="next" value="{{ next }}" />
</form>
</div>
</div>

{% edrn_boilerplate 'login-admonitions' %}
</div>
</div>
{% endblock %}
{# -*- Django HTML -*- #}
3 changes: 3 additions & 0 deletions src/edrn.auth/src/edrn/auth/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@
)),
path('logout/', LogoutView.as_view(), name='logout'),
path('authentication-test', authentication_test_view, name='authentication-test'),
path('_util/portal-login', auth_views.LoginView.as_view(
authentication_form=EDRNAuthenticationForm, template_name='edrn.auth/portal-login.html'
), name='portal_login')
]
20 changes: 17 additions & 3 deletions src/edrn.auth/src/edrn/auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,28 @@

'''🔐 EDRN auth: views.'''

from django.contrib.auth import views as auth_views
from django.http import HttpRequest, HttpResponse
from django.contrib import messages
from django.conf import settings
from django.contrib import messages
from django.contrib.auth import authenticate, login
from django.contrib.auth import views as auth_views
from django.http import HttpRequest, HttpResponse
from django.urls import reverse
import base64, http


def authentication_context(request) -> dict:
'''Give the dictionary of authentication-related context for use in a page template.'''
return {
'authenticated': request.user.is_authenticated,
'logout': reverse('logout') + '?next=' + request.path,
# The "login" page is the full login with all the alternative destinations
'login': reverse('wagtailcore_login') + '?next=' + request.path,
# The "portal_login" page has just portal-related login, no alternative destinations like the
# "secure" site or LabCAS.
'portal_login': reverse('portal_login') + '?next=' + request.path,
}


def view_or_basicauth(view, request: HttpRequest, test_func, realm: str = '', *args, **kwargs):
'''Check if a user is logged in or not or if there's HTTP basic authentication.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ <h4 class='alert-heading'><i class='bi bi-incognito'></i> Non-Public Biomarker<
<p>
{% if authenticated %}
Organ-specific information for this biomarker is currently being annotated or is "under review".
<a href='{{logout}}'>Logging out</a> and then <a href='{{login}}'>back in</a> using an account
<a href='{{logout}}'>Logging out</a> and then <a href='{{portal_login}}'>back in</a> using an account
with access may give you privileges to view additional information.
{% else %}
Organ-specific information for this biomarker is currently being annotated or is "under review".
<a href='{{login}}'>Logging in</a> may give you privileges to view additional information.
<a href='{{portal_login}}'>Logging in</a> may give you privileges to view additional information.
{% endif %}
Contact the <a href="mailto:[email protected]">Informatics Center</a> if you believe you
should have access.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ <h4 class='alert-heading'><i class='bi bi-incognito'></i> Non-Public Biomarkers
<p>
{% if authenticated %}
Organ-specific information for some biomarkers are currently being annotated or are "under review".
<a href='{{logout}}'>Logging out</a> and then <a href='{{login}}'>back in</a> using an account
<a href='{{logout}}'>Logging out</a> and then <a href='{{portal_login}}'>back in</a> using an account
with access may give you privileges to view additional information.
{% else %}
Organ-specific information for some biomarkers are currently being annotated or are "under review".
<a href='{{login}}'>Logging in</a> may give you privileges to view additional information.
<a href='{{portal_login}}'>Logging in</a> may give you privileges to view additional information.
{% endif %}
Contact the <a href="mailto:[email protected]">Informatics Center</a> if you believe you
should have access.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,15 @@
from django import template
from django.db.models.functions import Lower
from django.template.context import Context
from django.urls import reverse
from django.utils.text import slugify
from edrn.auth.views import authentication_context
from edrnsite.content.models import CertificationSnippet
from wagtail.admin.templatetags.wagtailuserbar import get_page_instance # Feels odd importing from here


register = template.Library()


def _authentication(request) -> dict:
return {
'authenticated': request.user.is_authenticated,
'logout': reverse('logout') + '?next=' + request.path,
'login': reverse('wagtailcore_login') + '?next=' + request.path
}


@register.inclusion_tag('eke.biomarkers/biomarker-basics.html', takes_context=True)
def biomarker_basics(context: Context) -> dict:
'''For rendering the "Basics" tab of a biomarker view.'''
Expand Down Expand Up @@ -111,13 +103,13 @@ def biomarker_organs(context: Context) -> dict:
def private_biomarker(context: Context) -> dict:
'''For explaining why portions of a biomarker aren't visible.'''
request = context.get('request')
return _authentication(request)
return authentication_context(request)


@register.inclusion_tag('eke.biomarkers/private-biomarkers.html', takes_context=True)
def private_biomarkers(context: Context) -> dict:
request = context.get('request')
return _authentication(request)
return authentication_context(request)


@register.inclusion_tag('eke.biomarkers/certification.html', takes_context=False)
Expand Down

0 comments on commit ceaaa36

Please sign in to comment.