@@ -75,12 +75,14 @@ def generate_token_for_email(email, user_agent='', ip_address=''):
75
75
break
76
76
77
77
# No active user found, raise a ValidationError
78
- # but not if DJANGO_REST_PASSWORDRESET_NO_INFORMATION_LEAKAGE == True
79
- if not active_user_found and not getattr (settings , 'DJANGO_REST_PASSWORDRESET_NO_INFORMATION_LEAKAGE' , False ):
80
- raise exceptions .ValidationError ({
81
- 'email' : [_ (
82
- "We couldn't find an account associated with that email. Please try a different e-mail address." )],
83
- })
78
+ # but not if DJANGO_REST_PASSWORDRESET_NO_INFORMATION_LEAKAGE == True, in that case we return None
79
+ if not active_user_found :
80
+ if not getattr (settings , 'DJANGO_REST_PASSWORDRESET_NO_INFORMATION_LEAKAGE' , False ):
81
+ raise exceptions .ValidationError ({
82
+ 'email' : [_ (
83
+ "We couldn't find an account associated with that email. Please try a different e-mail address." )],
84
+ })
85
+ return None
84
86
85
87
# last but not least: iterate over all users that are active and can change their password
86
88
# and create a Reset Password Token and send a signal with the created token
@@ -199,9 +201,13 @@ def post(self, request, *args, **kwargs):
199
201
ip_address = request .META .get (HTTP_IP_ADDRESS_HEADER , '' ),
200
202
)
201
203
202
- # send a signal that the password token was created
203
- # let whoever receives this signal handle sending the email for the password reset
204
- reset_password_token_created .send (sender = self .__class__ , instance = self , reset_password_token = token )
204
+ if token :
205
+ # send a signal that the password token was created
206
+ # let whoever receives this signal handle sending the email for the password reset
207
+ reset_password_token_created .send (
208
+ sender = self .__class__ ,
209
+ instance = self , reset_password_token = token
210
+ )
205
211
206
212
return Response ({'status' : 'OK' })
207
213
0 commit comments