mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2024-11-25 19:14:03 +03:00
Allow django-admin to optionally use django-allauth login workflow (#1921)
* Allow django-admin to optionally use django-allauth login workflow * Fix mypy and add a comment to allauth documentation --------- Co-authored-by: Bruno Alla <alla.brunoo@gmail.com>
This commit is contained in:
parent
ab29818ceb
commit
397100dcab
|
@ -81,3 +81,6 @@ Other Environment Settings
|
|||
|
||||
DJANGO_ACCOUNT_ALLOW_REGISTRATION (=True)
|
||||
Allow enable or disable user registration through `django-allauth` without disabling other characteristics like authentication and account management. (Django Setting: ACCOUNT_ALLOW_REGISTRATION)
|
||||
|
||||
DJANGO_ADMIN_FORCE_ALLAUTH (=False)
|
||||
Force the `admin` sign in process to go through the `django-allauth` workflow.
|
||||
|
|
|
@ -250,6 +250,9 @@ ADMIN_URL = "admin/"
|
|||
ADMINS = [("""{{cookiecutter.author_name}}""", "{{cookiecutter.email}}")]
|
||||
# https://docs.djangoproject.com/en/dev/ref/settings/#managers
|
||||
MANAGERS = ADMINS
|
||||
# https://cookiecutter-django.readthedocs.io/en/latest/settings.html#other-environment-settings
|
||||
# Force the `admin` sign in process to go through the `django-allauth` workflow
|
||||
DJANGO_ADMIN_FORCE_ALLAUTH = env.bool('DJANGO_ADMIN_FORCE_ALLAUTH', default=False)
|
||||
|
||||
# LOGGING
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
|
@ -1,12 +1,18 @@
|
|||
from django.conf import settings
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth import admin as auth_admin
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth import get_user_model, decorators
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from {{ cookiecutter.project_slug }}.users.forms import UserAdminChangeForm, UserAdminCreationForm
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
if settings.DJANGO_ADMIN_FORCE_ALLAUTH:
|
||||
# Force the `admin` sign in process to go through the `django-allauth` workflow:
|
||||
# https://django-allauth.readthedocs.io/en/stable/advanced.html#admin
|
||||
admin.site.login = decorators.login_required(admin.site.login) # type: ignore[method-assign]
|
||||
|
||||
|
||||
@admin.register(User)
|
||||
class UserAdmin(auth_admin.UserAdmin):
|
||||
|
|
Loading…
Reference in New Issue
Block a user