Skip to content

Commit

Permalink
"Forgot Password" error: Validates that the email exists in the datab…
Browse files Browse the repository at this point in the history
…ase (#444)

* Validates that the email exists in the database before retrieving password reset information. Also keeps the message constant whether the email exists or not.

* Reverts part of previous commit: Properly displays a message to notify users if the email address doesn't exist.
  • Loading branch information
jddanna committed Mar 27, 2021
1 parent 0a3e7cd commit cfdd525
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions applications/home/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,14 @@ def forgot_password_page(request):
if 'GET' == request.method:
return render(request, 'forgot_password/index.html', context) # Handle GET request to forgot password page.
elif 'POST' == request.method:
password_reset_code = users.add_user_to_password_reset(request, email=request.POST.get('forgot_email', None))
email = request.POST.get('forgot_email', None)

if password_reset_code is not None:
if users.get_user(request, email) is not None:
password_reset_code = users.add_user_to_password_reset(request, email)
users.send_password_reset_email(request, password_reset_code)
context["success_message"] = "You will receive an email with link to update the password!"
context["success_message"] = "You will receive an email with a link to update the password!"
else:
context["error_message"] = "You will receive an email with link to update the password!"
context["error_message"] = "No account is associated with that email address"
return render(request, 'forgot_password/index.html', context) # Handle POST request to forgot password page.
else:
raise MethodNotAllowed(request) # Handle other type of request methods like PUT, UPDATE.
Expand Down

0 comments on commit cfdd525

Please sign in to comment.