django-allauth icon indicating copy to clipboard operation
django-allauth copied to clipboard

Disable unique emails but allow USERNAME_EMAIL authentication method?

Open areebbeigh opened this issue 3 years ago • 4 comments

I want to be able to keep ACCOUNT_UNIQUE_EMAIL = False and still allow sign-ins with email.

Our user requires a unique-together constraint on user.email, user.type, so it's possbile for a user to have two accounts of different types with the same email. How we would handle signups/logins against the correct user types is by overriding allauth's AuthenticationBackend and check some platform specific info in the request object.

However, it seems the following in AppSettings is blocking this config:

https://github.com/pennersr/django-allauth/blob/353386216b79f16709e97bb487c0bbbba2bc0c71/allauth/account/app_settings.py#L23-L26

Is there any way around this? Or do you have any recommendations on how to handle such a use case?

Thanks.

areebbeigh avatar Apr 07 '21 08:04 areebbeigh

Seems inefficient if you think about it? It's merely the same user no? Allauth has an EmailAddress table so that a single account/User record has multiple emails if that helps.

Andrew-Chen-Wang avatar May 01 '21 19:05 Andrew-Chen-Wang

We have the same use case and stumbled onto this: we run a contest, the contest have different "seasons" and an User can subscribe multiple times, but only once per season. So we can filter all user queryset by season period and we want to keep intact the confirmation email flow and login by email, but this settings makes really difficult to achieve what we need.

Arussil avatar Feb 02 '22 09:02 Arussil

@Andrew-Chen-Wang This is what's called a natural key.


I would actually vote to remove this constraint, it can't be all to uncommon for users to want this kind of thing.

derek-adair avatar Sep 18 '23 01:09 derek-adair

If you don't take special care the combination of ACCOUNT_UNIQUE_EMAIL=False and login by email is a tricky one. So removing that constraint altogether may signal the wrong message, so I would prefer to use https://docs.djangoproject.com/en/4.2/topics/checks/ and turn it into a warning that can be silenced by people that know what they are getting into (settings.SILENCED_SYSTEM_CHECKS).

pennersr avatar Sep 18 '23 08:09 pennersr