Django-allauth: Is there a built-in way to limit users to a single email address?

Created on 28 Aug 2015  Â·  9Comments  Â·  Source: pennersr/django-allauth

My project doesn't have much use for multiple emails per user, so in the interest of simplicity we'd like to limit users to a single email address.

I realize I can probably accomplish this in a naive way by overriding the email_confirmed signal and deleting all other EmailAddresses and EmailConfirmations associated with the user, but is there a built-in way to achieve this?

Thanks for all the great work.

Most helpful comment

It seems that you can override urls if you listed before the default ones. I tried this and works so far.

from django.views.defaults import page_not_found
...
url(r"^accounts/email/$", page_not_found, name="account_email"),
url(r"^accounts/', include('allauth.urls')),
...

All 9 comments

Could you just remove the ui to add email addresses?
On 28 Aug 2015 10:00 pm, "Hakan Bakkalbasi" [email protected]
wrote:

My project doesn't have much use for multiple emails per user, so in the
interest of simplicity we'd like to limit users to a single email address.

I realize I can probably accomplish this in a naive way by overriding the
email_confirmed signal and deleting all other EmailAddresses and
EmailConfirmations associated with the user, but is there a built-in way to
achieve this?

Thanks for all the great work.

—
Reply to this email directly or view it on GitHub
https://github.com/pennersr/django-allauth/issues/1109.

The problem with this is that the endpoint /accounts/email is supported by the app which will give you 500 since the template was not found or something like that? I am not aware of a way to disable/override a specific url from an installed app.

It seems that you can override urls if you listed before the default ones. I tried this and works so far.

from django.views.defaults import page_not_found
...
url(r"^accounts/email/$", page_not_found, name="account_email"),
url(r"^accounts/', include('allauth.urls')),
...

There is no built-in way, but it is easy to accomplish as described above.

This issue is 4 years old but I have the same question. Allauth newb here... I set it up on a test project and I want to only allow users to have one email. Frankly, this is the only little thing that's preventing me from using the package, otherwise it seems great.

Is the technique above (overriding the urls) still the best way to do it? It seems like accounts/email is part of the logout menu, so would I have to change that template too?

Note that users should at all times be able to change their own email address without locking themselves out. So, users would need to be able to have at least two email addresses no matter what. The current one, and a new pending (unverified) one.

@pennersr Agree, but in my experience most sites have a simple form that lets you type in your new email address, and then a confirmation email is sent. If the confirmation is never clicked, the old email address remains.

I'd say most sites do it that way, although I just checked GitHub and they appear to show multiple address. However, I would argue that's mainly because they allow you to receive notifications on a different email than your main login email.

If allauth is opinionated about allowing multiple email addresses to be added, that's fine. I'm still learning. Just trying to figure out my different options or whether I need to write my own.

@ekerstein You do not need to expose the email management view, simply remove it from your urls.

It seems that you can override urls if you listed before the default ones. I tried this and works so far.

from django.views.defaults import page_not_found
...
url(r"^accounts/email/$", page_not_found, name="account_email"),
url(r"^accounts/', include('allauth.urls')),
...

page_not_found view now accepts a second parameter, the "exception" that triggered the error.
You may need to modify your code like this:-

from django.views.defaults import page_not_found

urlpatterns = [
    path('accounts/email/', page_not_found, {'exception': Exception('Not Found')}, name="account_email"),
    path('accounts/', include('allauth.urls')),
]
Was this page helpful?
0 / 5 - 0 ratings

Related issues

gitdeepak picture gitdeepak  Â·  5Comments

LukasKlement picture LukasKlement  Â·  4Comments

psychok7 picture psychok7  Â·  5Comments

nordbit picture nordbit  Â·  5Comments

eillarra picture eillarra  Â·  3Comments