Challenge: Creating Allauth-compliant Users with Admin Panel

I have a custom User in accounts.models.py which is a subclass of AbstractUser and I am able to create instances from the Admin Panel.

My accounts.admin.py looks like this:

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin

from .forms import CustomUserCreationForm, CustomUserChangeForm
from .models import User

class CustomUserAdmin(UserAdmin):
    add_form = CustomUserCreationForm
    add_fieldsets = (
        (
            None,
            {
                “classes”: (“wide”,),
                “fields”: (“username”, “email”, “password1”, “password2”),
            },
        ),
    )
    form = CustomUserChangeForm
    model = User
    list_display = [
        “email”,
        “username”,
    ]

admin.site.register(User, CustomUserAdmin)

This works. I mean, it creates users alright. The problem is that the Users doesn’t authenticate via allauth (and I am using allauth). I only see them on the Admin Panel but I cannot log into the project site with them. When I try, I get the error message:

The email address and/or password you specified are not correct.

Actually, the email and password are perfect. Allauth creates Users via a sign-up process. Currently, I would like to have Superusers (admins) create User accounts via the Admin Panel. The result should be accounts that allauth can authenticate – allowing the account owner to run account recovery or change passwords independently (later).

How do I do that?

From the docs at https://docs.allauth.org/en/latest/account/introduction.html:

The allauth.account app is responsible for managing regular accounts. It supports:

  • Registration of new users, with custom signup form support.

It looks like you would need to create your own view to do this, possibly with creating a custom form for the process. My guess is that allauth maintains additional data outside the normal auth module that prevents the basic admin form from being fully functional.

If you really want to pursue this angle, I suggest you dig into the allauth source code to see how they handle user-creation - you might be able to create a custom admin class to replicate that functionality.

1 Like

Thanks for the cue.

I perused the relevant allauth sources and arrived at the conclusion that the need does not justify the stress. I am now currently exploring the possibility of creating users directly via allauth’s SignupView then making that view accessible to Users with is_staff=True.

I wonder if one can disable the adding of Users from the Admin panel (i.e. add_form=None). So far, modifying existing users from the Panel works fine.

This too is futile, allauth immediately redirects to LOGIN_REDIRECT_URL specified in project/settings.py since a User is already logged in. There has to be a way to create an account as Proxy. Perhaps, an intermediate page (after the User initiates signup) requiring Staff approval and not the usual Email follow-up.

Found a related thread as per the current direction: