Skip to content

Commit

Permalink
confirm_password -> confirm_new_password (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
dantownsend committed Jun 17, 2022
1 parent 9bc1685 commit b99580f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/source/change_password/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ change their password manually.

Alternatively, you can change the password programatically by sending a POST
request to this endpoint (passing in ``old_password``, ``new_password`` and
``confirm_password`` parameters as JSON, or as form data).
``confirm_new_password`` parameters as JSON, or as form data).

When the password change is successful, we invalidate the session cookie, and
redirect the user to the login endpoint.
Expand Down
10 changes: 7 additions & 3 deletions piccolo_api/change_password/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,16 @@ async def post(self, request: Request) -> Response:

old_password = body.get("old_password", None)
new_password = body.get("new_password", None)
confirm_password = body.get("confirm_password", None)
confirm_new_password = body.get("confirm_new_password", None)

piccolo_user = request.user.user
min_password_length = piccolo_user._min_password_length

if (not old_password) or (not new_password) or (not confirm_password):
if (
(not old_password)
or (not new_password)
or (not confirm_new_password)
):
error = "Form is invalid. Missing one or more fields."
if body.get("format") == "html":
return self.render_template(
Expand All @@ -129,7 +133,7 @@ async def post(self, request: Request) -> Response:
detail=error,
)

if confirm_password != new_password:
if confirm_new_password != new_password:
error = "Passwords do not match."

if body.get("format") == "html":
Expand Down
2 changes: 1 addition & 1 deletion piccolo_api/templates/change_password.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ <h1>Change Password</h1>
<label>New Password ({{ min_password_length }} characters minimum)</label>
<input type="password" name="new_password" minlength={{ min_password_length }} required />
<label>Confirm New Password</label>
<input type="password" name="confirm_password" minlength={{ min_password_length }} required />
<input type="password" name="confirm_new_password" minlength={{ min_password_length }} required />

{% if csrftoken and csrf_cookie_name %}
<input type="hidden" name="{{ csrf_cookie_name }}" value="{{ csrftoken }}" />
Expand Down
10 changes: 5 additions & 5 deletions tests/session_auth/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ def test_correct_old_password(self):
json={
"old_password": f"{self.credentials['password']}",
"new_password": "newpass123",
"confirm_password": "newpass123",
"confirm_new_password": "newpass123",
},
)
self.assertEqual(response.status_code, 303)
Expand All @@ -495,7 +495,7 @@ def test_wrong_old_password(self):
json={
"old_password": "bob1234",
"new_password": "newpass123",
"confirm_password": "newpass123",
"confirm_new_password": "newpass123",
},
)
self.assertEqual(response.status_code, 401)
Expand All @@ -518,7 +518,7 @@ def test_change_password_success(self):
json={
"old_password": f"{self.credentials['password']}",
"new_password": "newpass123",
"confirm_password": "newpass123",
"confirm_new_password": "newpass123",
},
)
self.assertEqual(response.status_code, 303)
Expand Down Expand Up @@ -562,7 +562,7 @@ def test_change_password_length(self):
json={
"old_password": f"{self.credentials['password']}",
"new_password": "john",
"confirm_password": "john123",
"confirm_new_password": "john123",
},
)
self.assertEqual(response.status_code, 401)
Expand All @@ -587,7 +587,7 @@ def test_change_password_match(self):
json={
"old_password": f"{self.credentials['password']}",
"new_password": "john123",
"confirm_password": "john1234",
"confirm_new_password": "john1234",
},
)
self.assertEqual(response.status_code, 401)
Expand Down

0 comments on commit b99580f

Please sign in to comment.