-
Notifications
You must be signed in to change notification settings - Fork 101
Open
Labels
Description
Following the docs on "How To Create Users Without Setting Their Password" https://django-authtools.readthedocs.io/en/latest/how-to/invitation-email.html (relevant code snippet below), the call to reset_form.save
could trigger SMTPRecipientsRefused
if the recipient email address is invalid, currently it will result in a 500 as-is. My understanding is that usually form error validations are handled in the clean_*
method, any suggestions on how to deal with the SMTPRecipientsRefused
exception in this case?
def save_model(self, request, obj, form, change):
if not change and (not form.cleaned_data['password1'] or not obj.has_usable_password()):
# Django's PasswordResetForm won't let us reset an unusable
# password. We set it above super() so we don't have to save twice.
obj.set_password(get_random_string())
reset_password = True
else:
reset_password = False
super(UserAdmin, self).save_model(request, obj, form, change)
if reset_password:
reset_form = PasswordResetForm({'email': obj.email})
assert reset_form.is_valid()
reset_form.save(
request=request,
use_https=request.is_secure(),
subject_template_name='registration/account_creation_subject.txt',
email_template_name='registration/account_creation_email.html',
)