EmailUser considers a@b.com and a@B.com different users
See original GitHub issueThe domain part of an email address is case-insensitive. These days the local-part is considered case-sensitive too by nearly every email provider.
With EmailUser I was able to create two users in the admin with addresses a@b.com and a@B.com - this should be impossible, these should not be judged as unique.
I’m grappling with this in a project I’m working on, where users can type an email address to invite other users to a project - if they use a different case, then the user that already has an account gets another signup email! Not good. So I have to use get(email__iexact='...')
, but now I have the problem that get()
could crash since there could be multiple accounts returned!
Currently I’m ‘fixing’ with the following manager:
class UserManager(EmailUserManager):
def filter(self, **kwargs):
if 'email' in kwargs:
kwargs['email__iexact'] = kwargs['email']
del kwargs['email']
return super(UserManager, self).filter(**kwargs)
def get(self, **kwargs):
if 'email' in kwargs:
kwargs['email__iexact'] = kwargs['email']
del kwargs['email']
return super(UserManager, self).get(**kwargs)
But this feels pretty hacky and I’m concerned that these won’t pass to the queryset, so User.objects.get(email='...')
works fine but User.objects.filter(is_admin=True).filter(email='...')
won’t.
Any ideas on how this could be resolved and perhaps incorporated into django-custom-user?
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:11 (3 by maintainers)
Top GitHub Comments
Since Django 1.10 fields of abstract models can be overriden. So it should be as easy as following the instructions to extend EmailUser model and setting the email field there
Haven’t tried it, @assembledadam could you check if it works?
There was an interesting discussion in the django-developers mailing list regarding this same issue. Leaving this here for future reference: https://groups.google.com/d/topic/django-developers/SW7_qI81G58/discussion