pennersr / django-allauth

Integrated set of Django applications addressing authentication, registration, account management as well as 3rd party (social) account authentication.
https://allauth.org
MIT License
9.55k stars 3.03k forks source link

Can't delete primary email #290

Closed pjreddie closed 1 year ago

pjreddie commented 11 years ago

Even if an email is not required, you can't delete a primary email account and you can't make the email not primary unless you have one. So if you happen to click make primary once, you are forever stuck with some email (even if it isn't real) instead of having the option to delete all email addresses. It just seems like a strange design choice.

pennersr commented 11 years ago

It is a bit of a corner case. How about allowing users to delete their primary if and only if it is not verified? This way, you won't get "stuck forever" with a fake email.

numpde commented 5 years ago

I second the "strange design choice" opinion. The allauth framework is imposing too many constraints here. I want my visitors to be able to remove all e-mail if they want. With notifications and social login it is not necessary to have one and feels authoritarian. Thank you.

9mido commented 3 years ago

This code below will allow for the deletion of primary unverified emails.

It will also allow deletion of the last email with User.objects.filter(username=request.user).update(email="").

Views.py EmailView class _action_remove function:

from django.contrib.auth.models import User

            unverified_primary_email = EmailAddress.objects.filter(user=request.user,email=email, primary=True, verified=False).values_list('email', flat=True)
            if email_address.primary and email not in unverified_primary_email:
                get_adapter(request).add_message(
                    request,
                    messages.ERROR,
                    'account/messages/'
                    'cannot_delete_primary_email.txt',
                    {"email": email})
            elif email in unverified_primary_email:
                email_address.delete()
            else:
                email_address.delete()
                User.objects.filter(username=request.user).update(email="")
derek-adair commented 1 year ago

Close as per discussion in https://github.com/pennersr/django-allauth/pull/2774 (i think??). It seems like this is a corner case that can be solved w/ a custom adapter.

pennersr commented 1 year ago

No, this is a valid issue. If ACCOUNT_EMAIL_REQUIRED=False and ACCOUNT_AUTHENTICATION_METHOD="username" then indeed you should be able to delete all email addresses from your account.

derek-adair commented 1 year ago

Right but is that not solved by a custom adapter? Or did i misread your comment to mean it's worth modifying the core adapter to support this?

pennersr commented 1 year ago

It is an issue that can be worked around with by customizing things yourself, but this should indeed just work out of the box.

pennersr commented 1 year ago

Closed via a0ff1aa2