2

I'm using Django Registration Redux for user activation. From what I understand, the 'Active' field in the User model tracks whether or not the user has activated their account via the Django Registration Redux activation email, but doesn't do much else. Is this correct?

If so, how can I continue to use the built-in Django auth features to check if the user is logged in AND they have activated their account?

Thanks!

StringsOnFire
  • 2,726
  • 5
  • 28
  • 50

1 Answers1

2

The active flag can be set outside of Django Registration Redux. It can be toggled by administrators in the Django admin (e.g. change from active to inactive).

For example in Django's authentication docs I can see that:

  1. Only active users can reset their password
  2. The built in AuthenticationForm only allows active users to log in.

There may be other places that use the active flag as well.

The login_required decorator does not check the active flag. See this question for a way to check that the user is logged in and active.

If you have a custom user model, you could override the is_authenticated() method to check the is_active flag. Otherwise, you can do both checks in your view or template

{% if user.is_active and user.is_authenticated %}
Community
  • 1
  • 1
Alasdair
  • 298,606
  • 55
  • 578
  • 516
  • Thanks Alasdair. I thought this functionality might have improved over the last 3 years. Where would you put that code? – StringsOnFire Jul 22 '15 at 11:32
  • You can put the code wherever you want. Two options are in the `views.py` where you use it, or import it from a `decorators.py` module. – Alasdair Jul 22 '15 at 11:58