Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger password reset email in django without browser?

I want to be able to send a password reset email using django.contrib.auth.views.password_reset but without using the browser - password_reset needs a populated form, is there a way I can create this programmatically and get the email sent?

like image 930
Stuart Axon Avatar asked Apr 08 '11 11:04

Stuart Axon


2 Answers

from django.contrib.auth.forms import PasswordResetForm

def reset_password(email, from_email, template='registration/password_reset_email.html'):
    """
    Reset the password for all (active) users with given E-Mail adress
    """
    form = PasswordResetForm({'email': email})
    return form.save(from_email=from_email, email_template_name=template)
like image 163
ojii Avatar answered Nov 15 '22 02:11

ojii


You can just use django.contrib.auth.forms.PasswordResetForm and populate it with data like this:

form = PasswordResetForm({'email':'[email protected]'})

The sending of email is done upon save().

like image 22
gladysbixly Avatar answered Nov 15 '22 02:11

gladysbixly