| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from django.urls import URLPattern, URLResolver, include, path |
| 4 |
|
| 5 |
from allauth import app_settings as allauth_settings |
| 6 |
from allauth.account import app_settings as account_settings |
| 7 |
from allauth.headless.account import views |
| 8 |
from allauth.headless.constants import Client |
| 9 |
|
| 10 |
|
| 11 |
def build_urlpatterns(client: Client) -> list[URLPattern | URLResolver]: |
| 12 |
account_patterns: list[URLPattern | URLResolver] = [] |
| 13 |
auth_patterns: list[URLPattern | URLResolver] = [ |
| 14 |
path( |
| 15 |
"session", |
| 16 |
views.SessionView.as_api_view(client=client), |
| 17 |
name="current_session", |
| 18 |
), |
| 19 |
path( |
| 20 |
"reauthenticate", |
| 21 |
views.ReauthenticateView.as_api_view(client=client), |
| 22 |
name="reauthenticate", |
| 23 |
), |
| 24 |
path( |
| 25 |
"code/confirm", |
| 26 |
views.ConfirmLoginCodeView.as_api_view(client=client), |
| 27 |
name="confirm_login_code", |
| 28 |
), |
| 29 |
] |
| 30 |
if not allauth_settings.SOCIALACCOUNT_ONLY: |
| 31 |
account_patterns.extend( |
| 32 |
[ |
| 33 |
path( |
| 34 |
"password/change", |
| 35 |
views.ChangePasswordView.as_api_view(client=client), |
| 36 |
name="change_password", |
| 37 |
), |
| 38 |
path( |
| 39 |
"email", |
| 40 |
views.ManageEmailView.as_api_view(client=client), |
| 41 |
name="manage_email", |
| 42 |
), |
| 43 |
path( |
| 44 |
"phone", |
| 45 |
views.ManagePhoneView.as_api_view(client=client), |
| 46 |
name="manage_phone", |
| 47 |
), |
| 48 |
] |
| 49 |
) |
| 50 |
auth_patterns.extend( |
| 51 |
[ |
| 52 |
path( |
| 53 |
"password/", |
| 54 |
include( |
| 55 |
[ |
| 56 |
path( |
| 57 |
"request", |
| 58 |
views.RequestPasswordResetView.as_api_view( |
| 59 |
client=client |
| 60 |
), |
| 61 |
name="request_password_reset", |
| 62 |
), |
| 63 |
path( |
| 64 |
"reset", |
| 65 |
views.ResetPasswordView.as_api_view(client=client), |
| 66 |
name="reset_password", |
| 67 |
), |
| 68 |
] |
| 69 |
), |
| 70 |
), |
| 71 |
path( |
| 72 |
"login", |
| 73 |
views.LoginView.as_api_view(client=client), |
| 74 |
name="login", |
| 75 |
), |
| 76 |
path( |
| 77 |
"signup", |
| 78 |
views.SignupView.as_api_view(client=client), |
| 79 |
name="signup", |
| 80 |
), |
| 81 |
path( |
| 82 |
"email/verify", |
| 83 |
views.VerifyEmailView.as_api_view(client=client), |
| 84 |
name="verify_email", |
| 85 |
), |
| 86 |
path( |
| 87 |
"email/verify/resend", |
| 88 |
views.ResendEmailVerificationCodeView.as_api_view(client=client), |
| 89 |
name="resend_email_verification_code", |
| 90 |
), |
| 91 |
path( |
| 92 |
"phone/verify", |
| 93 |
views.VerifyPhoneView.as_api_view(client=client), |
| 94 |
name="verify_phone", |
| 95 |
), |
| 96 |
path( |
| 97 |
"phone/verify/resend", |
| 98 |
views.ResendPhoneVerificationCodeView.as_api_view(client=client), |
| 99 |
name="resend_phone_verification_code", |
| 100 |
), |
| 101 |
] |
| 102 |
) |
| 103 |
if account_settings.LOGIN_BY_CODE_ENABLED: |
| 104 |
auth_patterns.extend( |
| 105 |
[ |
| 106 |
path( |
| 107 |
"code/request", |
| 108 |
views.RequestLoginCodeView.as_api_view(client=client), |
| 109 |
name="request_login_code", |
| 110 |
), |
| 111 |
path( |
| 112 |
"code/resend", |
| 113 |
views.ResendLoginCodeView.as_api_view(client=client), |
| 114 |
name="resend_login_code", |
| 115 |
), |
| 116 |
] |
| 117 |
) |
| 118 |
return [ |
| 119 |
path("auth/", include(auth_patterns)), |
| 120 |
path( |
| 121 |
"account/", |
| 122 |
include(account_patterns), |
| 123 |
), |
| 124 |
] |