forms.py 893 B

123456789101112131415161718192021222324252627
  1. from dj_rest_auth.forms import AllAuthPasswordResetForm
  2. from django.contrib.auth import get_user_model
  3. from django.contrib.auth.forms import _unicode_ci_compare
  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. **{
  15. "%s__iexact" % email_field_name: email,
  16. "is_active": True,
  17. }
  18. )
  19. return (
  20. u
  21. for u in active_users
  22. if _unicode_ci_compare(email, getattr(u, email_field_name))
  23. )