forms.py 847 B

123456789101112131415161718192021222324
  1. from django.contrib.auth.forms import _unicode_ci_compare
  2. from django.contrib.auth import get_user_model
  3. from dj_rest_auth.forms import AllAuthPasswordResetForm
  4. UserModel = get_user_model()
  5. """
  6. Overriding this because the original filtered out users who didn't have a usable
  7. password. This includes social auth users, and we want to give them the option
  8. to set a password if they want to disconnect.
  9. """
  10. class PasswordSetAndResetForm(AllAuthPasswordResetForm):
  11. def get_users(self, email):
  12. email_field_name = UserModel.get_email_field_name()
  13. active_users = UserModel._default_manager.filter(
  14. **{"%s__iexact" % email_field_name: email, "is_active": True,}
  15. )
  16. return (
  17. u
  18. for u in active_users
  19. if _unicode_ci_compare(email, getattr(u, email_field_name))
  20. )