Allauth customization to not set user active and trigger email with signal email_confirmed

I am not having any luck finding examples of using Allauth for email verification but not setting the user to active until the administrator approves. My use case is member signup, get an email verification and then once the email is confirmed sending and email to the admins via the email_confirmed signal so they can go in and set the user active.

Any links, help or guidance would be much appreciated.
(still fairly new to django/python but have found a new love in the platform)
Thank you

If you are using django.allauth the a way to go is the adapter, https://github.com/pennersr/django-allauth/blob/master/allauth/account/adapter.py, the class is DefaultAccountAdpter, you can override the save_user method by user.is_active = False, and confirm_email method there you should send the email to the admin, if I understand well. the last thing is to tell django-allauth to use your custom adapter in the settings.

1 Like

Wouldn’t I just tap into the email_confirmed signal instead of overriding the confirm_email method in the new adapter class? As for the save_user method would I need to build the method the same or can I just override part of the method by adding:

Class NewAdapter(DefaultAdapter):

def save_user
user.is_active=true

OR do I need

def save_user(self, request, user, form, commit=True):
from .utils import user_email, user_field, user_username

   data = form.cleaned_data
    first_name = data.get("first_name")
    last_name = data.get("last_name")
    email = data.get("email")
    username = data.get("username")
    user_email(user, email)
    user_username(user, username)
    **user.is_active=False**
    if first_name:
        user_field(user, "first_name", first_name)
    if last_name:
        user_field(user, "last_name", last_name)
    if "password1" in data:
        user.set_password(data["password1"])
    else:
        user.set_unusable_password()
    self.populate_username(request, user)
    if commit:
        # Ability not to commit makes it easier to derive from
        # this adapter by adding
        user.save()
    return user

well you need something

def save_user(self,request,user, form,commit=True):
    # get the user from super save
    user = super().save_user(request, user, form,commit)
    user.is_active = False
    # make sure you save
    user.save()
    return user   

you can even not commit from the super save

I finally got around to implementing a custom adapter and it not going as planned. The save method is creating the user as in_active as expected but the rest of the email verification process is not proceeding. Email verification is set to mandatory. The oddity is that once a new user signs up they are immediately redirected to the /account/inactive/ route/url. I tried to create a customer redirect URL in the custom adapter def get_signup_redirect_url(self, request) per the docs and that is not even redirecting following the new user creations. I have also set the ACCOUNT_SIGNUP_REDIRECT_URL = and that is not even redirecting post signup.

Not sure what else to try/build/modify to get the workflow to happen. The end goal is to have a user sign up and verify their email address but not be able to log in until the administrator makes them active. I want to hook into the email confirmation signal of allauth to alert the admin’s of a new user signing up with a “valid/confirmed” email and then allow them to go into the admin panel and mark these new people active at which point they will be able to login normally.

Any help would be greatly appreciated.