Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Don't prefix the account URLs with language code

Roland Geider161b698aabb7
diff --git a/wger/core/tests/test_auth_social.py b/wger/core/tests/test_auth_social.py
index 911737a3d..de699f552 100644
--- a/wger/core/tests/test_auth_social.py
+++ b/wger/core/tests/test_auth_social.py
@@ -23,6 +23,7 @@ from django.test import (
override_settings,
)
from django.urls import reverse
+from django.utils import translation
# wger
from wger.core.tests.base_testcase import WgerTestCase
@@ -91,3 +92,21 @@ class WgerLoginViewContextTestCase(TestCase):
def test_use_social_auth_true_when_providers_configured(self):
ctx = self._build_view().get_context_data()
self.assertTrue(ctx['use_social_auth'])
+
+
+class AccountUrlLanguagePrefixTestCase(WgerTestCase):
+ """
+ allauth's account URLs (including the providers' OAuth callback) are mounted
+ without a language prefix so the redirect_uri registered with the provider
+ stays stable, yet the pages remain localized via LocaleMiddleware.
+ """
+
+ @translation.override('de')
+ def test_account_urls_have_no_language_prefix(self):
+ self.assertEqual(reverse('account_login'), '/account/login/')
+
+ def test_account_page_is_localized_from_accept_language(self):
+ """Without a URL prefix the page language comes from Accept-Language."""
+ response = self.client.get(reverse('account_login'), headers={'accept-language': 'de'})
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.headers['Content-Language'], 'de')
diff --git a/wger/urls.py b/wger/urls.py
index b1832b7e8..4b1094d9a 100644
--- a/wger/urls.py
+++ b/wger/urls.py
@@ -289,7 +289,6 @@ urlpatterns = i18n_patterns(
{'sitemaps': sitemaps},
name='django.contrib.sitemaps.views.sitemap',
),
- path('account/', include('allauth.urls')),
)
#
@@ -298,7 +297,12 @@ urlpatterns = i18n_patterns(
urlpatterns += [
path('i18n/', include('django.conf.urls.i18n')),
path('robots.txt', TextTemplateView.as_view(template_name='robots.txt'), name='robots'),
- # allauth.headless — REST auth API consumed by the Flutter app.
+
+ # allauth account pages are mounted without a language prefix: the OAuth
+ # callback's redirect_uri has to be stable
+ path('account/', include('allauth.urls')),
+
+ # REST auth API consumed by the Flutter app.
path('_allauth/', include('allauth.headless.urls')),
# API
path(