Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable unique emails but allow USERNAME_EMAIL authentication method? #2827

Open
areebbeigh opened this issue Apr 7, 2021 · 4 comments
Open

Comments

@areebbeigh
Copy link

areebbeigh commented Apr 7, 2021

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:

# If login includes email, login must be unique
assert (
self.AUTHENTICATION_METHOD == self.AuthenticationMethod.USERNAME
) or self.UNIQUE_EMAIL

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

Thanks.

@Andrew-Chen-Wang
Copy link
Contributor

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.

@Arussil
Copy link

Arussil commented Feb 2, 2022

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.

@derek-adair
Copy link

@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.

@pennersr
Copy link
Owner

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants