add kwargs template_base to LoginView (#35083)
This commit is contained in:
parent
b673b3a7fe
commit
d5e5701899
|
@ -1,4 +1,4 @@
|
|||
{% extends "base.html" %}
|
||||
{% extends template_base|default:"base.html" %}
|
||||
|
||||
{% block extra_scripts %}
|
||||
{% block mellon_extra_scripts %}
|
||||
|
|
|
@ -124,6 +124,10 @@ class ProfileMixin(object):
|
|||
|
||||
|
||||
class LoginView(ProfileMixin, LogMixin, View):
|
||||
@property
|
||||
def template_base(self):
|
||||
return self.kwargs.get('template_base', 'base.html')
|
||||
|
||||
def get_idp(self, request):
|
||||
entity_id = request.POST.get('entityID') or request.GET.get('entityID')
|
||||
if not entity_id:
|
||||
|
@ -182,6 +186,7 @@ class LoginView(ProfileMixin, LogMixin, View):
|
|||
next_url = error_url or self.get_next_url(default=resolve_url(settings.LOGIN_REDIRECT_URL))
|
||||
return render(request, 'mellon/authentication_failed.html',
|
||||
{
|
||||
'template_base': self.template_base,
|
||||
'debug': settings.DEBUG,
|
||||
'reason': reason,
|
||||
'status_codes': status_codes,
|
||||
|
@ -249,12 +254,15 @@ class LoginView(ProfileMixin, LogMixin, View):
|
|||
self.log.warning('user %s (NameID is %r) is inactive, login refused', user,
|
||||
attributes['name_id_content'])
|
||||
return render(request, 'mellon/inactive_user.html', {
|
||||
'template_base': self.template_base,
|
||||
'user': user,
|
||||
'saml_attributes': attributes})
|
||||
else:
|
||||
self.log.warning('no user found for NameID %r', attributes['name_id_content'])
|
||||
return render(request, 'mellon/user_not_found.html',
|
||||
{'saml_attributes': attributes})
|
||||
return render(request, 'mellon/user_not_found.html', {
|
||||
'template_base': self.template_base,
|
||||
'saml_attributes': attributes
|
||||
})
|
||||
request.session['lasso_session_dump'] = login.session.dump()
|
||||
|
||||
return HttpResponseRedirect(next_url)
|
||||
|
@ -374,7 +382,8 @@ class LoginView(ProfileMixin, LogMixin, View):
|
|||
url = app_settings.DISCOVERY_SERVICE_URL
|
||||
params = {
|
||||
# prevent redirect loops with the discovery service
|
||||
'entityID': request.build_absolute_uri(reverse('mellon_metadata')),
|
||||
'entityID': request.build_absolute_uri(
|
||||
reverse('mellon_metadata')),
|
||||
'return': return_url,
|
||||
}
|
||||
if is_passive:
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
<html>
|
||||
<body>
|
||||
<p>Theme is ok</p>
|
||||
{% block content %}
|
||||
{% endblock %}
|
||||
</body>
|
||||
</html>
|
|
@ -23,6 +23,7 @@ import xml.etree.ElementTree as ET
|
|||
|
||||
import lasso
|
||||
|
||||
import pytest
|
||||
from pytest import fixture
|
||||
|
||||
from django.utils import six
|
||||
|
@ -221,6 +222,27 @@ def test_sso_request_denied(db, app, idp, caplog, sp_settings):
|
|||
u'urn:oasis:names:tc:SAML:2.0:status:RequestDenied']" in caplog.text
|
||||
|
||||
|
||||
@pytest.mark.urls('urls_tests_template_base')
|
||||
def test_template_base(db, app, idp, caplog, sp_settings):
|
||||
response = app.get(reverse('mellon_login'))
|
||||
url, body, relay_state = idp.process_authn_request_redirect(
|
||||
response['Location'],
|
||||
auth_result=False,
|
||||
msg='User is not allowed to login')
|
||||
response = app.post(reverse('mellon_login'), params={'SAMLResponse': body, 'RelayState': relay_state})
|
||||
assert 'Theme is ok' in response.text
|
||||
|
||||
|
||||
def test_no_template_base(db, app, idp, caplog, sp_settings):
|
||||
response = app.get(reverse('mellon_login'))
|
||||
url, body, relay_state = idp.process_authn_request_redirect(
|
||||
response['Location'],
|
||||
auth_result=False,
|
||||
msg='User is not allowed to login')
|
||||
response = app.post(reverse('mellon_login'), params={'SAMLResponse': body, 'RelayState': relay_state})
|
||||
assert 'Theme is ok' not in response.text
|
||||
|
||||
|
||||
def test_sso_request_denied_artifact(db, app, caplog, sp_settings, idp_metadata, idp_private_key, rf):
|
||||
sp_settings.MELLON_DEFAULT_ASSERTION_CONSUMER_BINDING = 'artifact'
|
||||
request = rf.get('/')
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
# django-mellon - SAML2 authentication for Django
|
||||
# Copyright (C) 2014-2019 Entr'ouvert
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from django.conf.urls import url, include
|
||||
from django.http import HttpResponse
|
||||
|
||||
|
||||
def homepage(request):
|
||||
return HttpResponse('ok')
|
||||
|
||||
urlpatterns = [
|
||||
url('^', include('mellon.urls'), kwargs={'template_base': 'theme.html'}),
|
||||
url('^$', homepage, name='homepage'),
|
||||
]
|
Loading…
Reference in New Issue