Repository: valohai/django-allauth-2fa (language: python)

Issue:
Clean-up URLs
The URLs we include are kind of a mess:
- Some use dashes, others underscores
- None of them have a trailing slash
- Some are sub-directories, others are not

Theoretically we can just change these if people use names, but we would probably want to include redirects. It could also be nice to use a namespace.



Discussion / hints:
Wouldn't following this be able to help with the redirecting apsect?

https://stackoverflow.com/questions/14959217/django-url-redirect

https://stackoverflow.com/questions/15706489/redirect-to-named-url-pattern-directly-from-urls-py-in-django


1.0 should just drop the "old" URLs (that don't have trailing slashes).
> 1.0 should just drop the "old" URLs (that don't have trailing slashes).

Oh yes please!

Fix patch:
diff --git a/allauth_2fa/urls.py b/allauth_2fa/urls.py
index 4f09e80..09b5f78 100644
--- a/allauth_2fa/urls.py
+++ b/allauth_2fa/urls.py
@@ -1,25 +1,25 @@
-from django.urls import re_path
+from django.urls import path
 
 from allauth_2fa import views
 
 urlpatterns = [
-    re_path(
-        r"^two-factor-authenticate/?$",
+    path(
+        "authenticate/",
         views.TwoFactorAuthenticate.as_view(),
         name="two-factor-authenticate",
     ),
-    re_path(
-        r"^two_factor/setup/?$",
+    path(
+        "setup/",
         views.TwoFactorSetup.as_view(),
         name="two-factor-setup",
     ),
-    re_path(
-        r"^two_factor/backup_tokens/?$",
+    path(
+        "backup-tokens/",
         views.TwoFactorBackupTokens.as_view(),
         name="two-factor-backup-tokens",
     ),
-    re_path(
-        r"^two_factor/remove/?$",
+    path(
+        "remove/",
         views.TwoFactorRemove.as_view(),
         name="two-factor-remove",
     ),
diff --git a/docs/installation.rst b/docs/installation.rst
index e0d83f0..2be1801 100644
--- a/docs/installation.rst
+++ b/docs/installation.rst
@@ -78,7 +78,7 @@ Finally, you must include the django-allauth-2fa URLs:
 
     urlpatterns = [
         # Include the allauth and 2FA urls from their respective packages.
-        path('accounts/', include('allauth_2fa.urls')),
+        path('accounts/two-factor/', include('allauth_2fa.urls')),
         path('accounts/', include('allauth.urls')),
     ]
 


Test patch:
diff --git a/tests/test_allauth_2fa.py b/tests/test_allauth_2fa.py
index 2457919..77ab8b3 100644
--- a/tests/test_allauth_2fa.py
+++ b/tests/test_allauth_2fa.py
@@ -266,23 +266,6 @@ def test_anonymous(client):
         )
 
 
-def test_backwards_compatible_url(client, john_with_totp, user_logged_in_count):
-    """Ensure that the old 2FA URLs still work."""
-    # TODO(1.0): remove this test
-    user, totp_device = john_with_totp
-    login(client, expected_redirect_url=TWO_FACTOR_AUTH_URL)
-    # The old URL doesn't have a trailing slash.
-    do_totp_authentication(
-        client,
-        totp_device=totp_device,
-        auth_url=str(TWO_FACTOR_AUTH_URL).rstrip("/"),
-        expected_redirect_url=settings.LOGIN_REDIRECT_URL,
-    )
-
-    # Ensure the signal is received as expected.
-    assert user_logged_in_count() == 1
-
-
 def test_not_configured_redirect(client, john):
     """Viewing backup codes or disabling 2FA should redirect if 2FA is not
     configured."""
diff --git a/tests/urls.py b/tests/urls.py
index 7e11d54..5cb6ff8 100644
--- a/tests/urls.py
+++ b/tests/urls.py
@@ -15,7 +15,7 @@ def login_required_view(request):
 
 urlpatterns = [
     # Include the allauth and 2FA urls from their respective packages.
-    path("accounts/", include("allauth_2fa.urls")),
+    path("accounts/2fa/", include("allauth_2fa.urls")),
     path("accounts/", include("allauth.urls")),
     # A view without a name.
     path("unnamed-view", blank_view),