File size: 611 Bytes
727a40a
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
from django.contrib.auth.models import User
from django.contrib.auth import views as auth_views

class CustomPasswordResetView(auth_views.PasswordResetView):
    template_name = './password/password_reset_form.html'
    email_template_name = './password/password_reset_email.html'

    def form_valid(self, form):
        email = form.cleaned_data['email']
        if not User.objects.filter(email=email).exists():
            form.add_error(
                'email', 'This email is not associated with any user in our system.')
            return self.form_invalid(form)
        return super().form_valid(form)