Closed pjreddie closed 1 year 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.
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.
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="")
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.
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.
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?
It is an issue that can be worked around with by customizing things yourself, but this should indeed just work out of the box.
Closed via a0ff1aa2
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.