Skip to content

Commit 4233209

Browse files
committed
refactor conditional for cleaner execution path
1 parent 4ff7182 commit 4233209

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

django_rest_passwordreset/views.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,12 @@ def post(self, request, *args, **kwargs):
118118
active_user_found = True
119119

120120
# No active user found, raise a validation error
121-
if not active_user_found:
122-
# if we dont want it to be known whether or not the email account
123-
# exists in the db then we just return 200
124-
if getattr(settings, 'DJANGO_REST_PASSWORDRESET_NO_INFORMATION_LEAKAGE', False):
125-
return Response({'status': 'OK'})
126-
else:
127-
raise exceptions.ValidationError({
128-
'email': [_(
129-
"There is no active user associated with this e-mail address or the password can not be changed")],
130-
})
121+
# but not if DJANGO_REST_PASSWORDRESET_NO_INFORMATION_LEAKAGE == True
122+
if not active_user_found and not getattr(settings, 'DJANGO_REST_PASSWORDRESET_NO_INFORMATION_LEAKAGE', False):
123+
raise exceptions.ValidationError({
124+
'email': [_(
125+
"There is no active user associated with this e-mail address or the password can not be changed")],
126+
})
131127

132128
# last but not least: iterate over all users that are active and can change their password
133129
# and create a Reset Password Token and send a signal with the created token

0 commit comments

Comments
 (0)