django-allauth
django-allauth copied to clipboard
Disable unique emails but allow USERNAME_EMAIL authentication method?
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.
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.
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.
@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.
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
).