Question

I'm trying to use django's supposed PasswordResetForm functionality to create a password reset form for my django application.

I created a form, in forms.py

class UserForgotPasswordForm(PasswordResetForm):
    email = forms.EmailField(required=True,max_length=254)
    class Meta:
        model = User
        fields = ("email")

I'm having trouble setting up the view in views.py to utilize this form, I currently have:

def UserResetPassword(request):
    form = UserForgotPasswordForm(None, request.POST)
    if request.method == 'POST':
        if form.is_valid():
            email = request.POST.get('email', '')
            user = 

my urls.py

urlpatterns = patterns('',
    (r'^ForgotPassword/$',UserResetPassword),
)

I'm at a bit of a loss of how to use this further as the documentation I've found is scarce and often not directly using PasswordResetForm django functionality.

Can someone lend a hand?

Thank you.

Was it helpful?

Solution

I believe all you need to do is call form.save() and the PasswordResetForm will generate a onetime use link and email it to the user for you. It looks up the user matching the e-mail entered into the form.

So it would be something like:

def UserResetPassword(request):
    form = UserForgotPasswordForm(None, request.POST)
    if request.method == 'POST':
        if form.is_valid():
            form.save(from_email='blah@blah.com', email_template_name='path/to/your/email_template.html')

If you don't specify an email template name, django will just use the default one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top