question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

EmailUser considers a@b.com and a@B.com different users

See original GitHub issue

The 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:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jcugatcommented, Dec 12, 2017

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

from django.contrib.postgres.fields import CIEmailField

class CaseInsensitiveEmailUser(AbstractEmailUser):
    email = CIEmailField(_('email address'), max_length=255, unique=True, db_index=True)

Haven’t tried it, @assembledadam could you check if it works?

2reactions
jcugatcommented, Feb 17, 2016

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Symbolab Privacy Policy
To enable Course Hero, Inc. to allow users to sign up for and sign in to multiple services across Course Hero Companies at...
Read more >
A/B test your marketing email - HubSpot Knowledge Base
An A/B test measures engagement for different versions of the same email with a sample of your recipients. After creating your marketing ...
Read more >
Setting up Answer Bot triggers, views, and workflows
Figuring out the best way to set up Answer Bot triggers, automations, views, and tags can be confusing for a lot of users....
Read more >
draft-ietf-secevent-subject-identifiers-04
Below is a non-normative example Subject Identifier for the Email Subject Identifier Type: { "subject_type": "email", "email": "user@example.com", } ...
Read more >
BIMobject Privacy Notice for California Residents
We, BIMobject AB and our Affiliates, specifically, but not limited to, ... or considered, or other purchasing or consuming histories or tendencies.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found