Search code examples
djangodjango-registration

django-registration send email when user is set as active


I have a use case, for which django-registration provides most of the required functionality. I need to do something "extra" though. By default django-registration supports this workflow:

  1. A user signs up for an account by supplying a username, email address and password.
  2. From this information, a new User object is created, with its is_active field set to False. Additionally, an activation key is generated and stored, and an email is sent to the user containing a link to click to activate the account.
  3. Upon clicking the activation link, the new account is made active (the is_active field is set to True); after this, the user can log in.

I need to send a "getting started" email after (or as part of) Step 3; i.e. when a user account becomes "active" (i.e. when "activation" is "complete" from a django-registration standpoint).

How do I insert this within the workflow above? I would like to use django-registration and avoid reinventing the wheel.


Solution

  • django-registration provides the user_activated signal (read here).

    The signal should be intercepted using the following code:

    from registration.signals import user_activated
    from django.dispatch import receiver
    
    @receiver(user_activated)
    def my_callback(sender, user, request):
        # handle signal