From 8d483aa45b8d97326feff71c2f1735647f94e68b Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Sat, 23 Apr 2022 15:03:21 +0200 Subject: [PATCH] context_processors: adapt user_urls for authentic (#62335) --- hobo/context_processors.py | 7 +++++++ tests/test_context_processors.py | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/hobo/context_processors.py b/hobo/context_processors.py index 0904989..42a22de 100644 --- a/hobo/context_processors.py +++ b/hobo/context_processors.py @@ -214,4 +214,11 @@ def user_urls(request): context['registration_url'] = ( template_vars['idp_registration_url'] + '?' + urlencode({'next': absolute_uri}) ) + if 'authentic2' in settings.INSTALLED_APPS: + if request.path == '/login/': + context['login_url'] = '#' + context['registration_url'] = '/register/?' + request.GET.urlencode() + if request.path == '/register/': + context['login_url'] = '/login/?' + request.GET.urlencode() + context['registration_url'] = '#' return context diff --git a/tests/test_context_processors.py b/tests/test_context_processors.py index e3f808b..1af68d5 100644 --- a/tests/test_context_processors.py +++ b/tests/test_context_processors.py @@ -81,3 +81,22 @@ def test_user_urls(settings, rf): 'registration_url': 'https://idp/register/?next=http%3A%2F%2Ftestserver%2Fpage%2F', 'account_url': 'https://idp/accounts/?next=http%3A%2F%2Ftestserver%2Fpage%2F', } + + from django.conf import settings as real_settings + + real_settings.INSTALLED_APPS += ('authentic2',) + request = rf.get('/login/?next=coin&nonce=2') + assert user_urls(request) == { + 'login_url': '#', + 'logout_url': '/logout/?next=%2F', + 'registration_url': '/register/?next=coin&nonce=2', + 'account_url': 'https://idp/accounts/?next=http%3A%2F%2Ftestserver%2Flogin%2F%3Fnext%3Dcoin%26nonce%3D2', + } + + request = rf.get('/register/?next=coin&nonce=2') + assert user_urls(request) == { + 'login_url': '/login/?next=coin&nonce=2', + 'logout_url': '/logout/?next=%2F', + 'registration_url': '#', + 'account_url': 'https://idp/accounts/?next=http%3A%2F%2Ftestserver%2Fregister%2F%3Fnext%3Dcoin%26nonce%3D2', + }