2024-01-25 15:33:24 +01:00
|
|
|
from django.urls import include, path, re_path
|
2017-12-29 18:19:01 +01:00
|
|
|
from django.utils.module_loading import import_string
|
2017-07-25 18:31:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
def default_urlpatterns(provider):
|
|
|
|
package = provider.get_package()
|
|
|
|
|
2017-12-29 18:19:01 +01:00
|
|
|
try:
|
2024-01-25 15:33:24 +01:00
|
|
|
login_view = import_string(package + ".views.login")
|
2017-12-29 18:19:01 +01:00
|
|
|
except ImportError:
|
|
|
|
raise ImportError(
|
|
|
|
"The login view for the '{id}' provider is lacking from the "
|
|
|
|
"'views' module of its app.\n"
|
|
|
|
"You may want to add:\n"
|
|
|
|
"from allauth_cas.views import CASLoginView\n\n"
|
2024-01-25 15:33:24 +01:00
|
|
|
"login = CASLoginView.adapter_view(<LocalCASAdapter>)".format(
|
|
|
|
id=provider.id
|
|
|
|
)
|
2017-12-29 18:19:01 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
try:
|
2024-01-25 15:33:24 +01:00
|
|
|
callback_view = import_string(package + ".views.callback")
|
2017-12-29 18:19:01 +01:00
|
|
|
except ImportError:
|
|
|
|
raise ImportError(
|
|
|
|
"The callback view for the '{id}' provider is lacking from the "
|
|
|
|
"'views' module of its app.\n"
|
|
|
|
"You may want to add:\n"
|
|
|
|
"from allauth_cas.views import CASCallbackView\n\n"
|
2024-01-25 15:33:24 +01:00
|
|
|
"callback = CASCallbackView.adapter_view(<LocalCASAdapter>)".format(
|
|
|
|
id=provider.id
|
|
|
|
)
|
2017-12-29 18:19:01 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
try:
|
2024-01-25 15:33:24 +01:00
|
|
|
logout_view = import_string(package + ".views.logout")
|
2017-12-29 18:19:01 +01:00
|
|
|
except ImportError:
|
|
|
|
logout_view = None
|
2017-07-25 18:31:42 +02:00
|
|
|
|
|
|
|
urlpatterns = [
|
2024-01-25 15:33:24 +01:00
|
|
|
path("login/", login_view, name=provider.id + "_login"),
|
|
|
|
path("login/callback/", callback_view, name=provider.id + "_callback"),
|
2017-07-25 18:31:42 +02:00
|
|
|
]
|
|
|
|
|
2017-12-29 18:19:01 +01:00
|
|
|
if logout_view is not None:
|
|
|
|
urlpatterns += [
|
2024-01-25 15:33:24 +01:00
|
|
|
path("logout/", logout_view, name=provider.id + "_logout"),
|
2017-12-29 18:19:01 +01:00
|
|
|
]
|
|
|
|
|
2024-01-25 15:33:24 +01:00
|
|
|
return [re_path("^" + provider.get_slug() + "/", include(urlpatterns))]
|