Skip to content

Commit

Permalink
old password -> current password (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
dantownsend committed Jun 18, 2022
1 parent 88ea687 commit eeea268
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions piccolo_api/change_password/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ async def post(self, request: Request) -> Response:
except JSONDecodeError:
body = await request.form()

old_password = body.get("old_password", None)
current_password = body.get("current_password", None)
new_password = body.get("new_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)
(not current_password)
or (not new_password)
or (not confirm_new_password)
):
Expand Down Expand Up @@ -146,7 +146,7 @@ async def post(self, request: Request) -> Response:
raise HTTPException(status_code=401, detail=error)

if not await piccolo_user.login(
username=piccolo_user.username, password=old_password
username=piccolo_user.username, password=current_password
):
error = "Incorrect password."
if body.get("format") == "html":
Expand Down
4 changes: 2 additions & 2 deletions piccolo_api/templates/change_password.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ <h1>Change Password</h1>
<p class="hint">Logged in as {{ username }}.</p>

<form method="POST">
<label>Old Password</label>
<input type="password" name="old_password" required />
<label>Current Password</label>
<input type="password" name="current_password" required />
<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>
Expand Down
14 changes: 7 additions & 7 deletions tests/session_auth/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def test_change_password_get_template(self):
)
self.assertTrue(b"<h1>Change Password</h1>" in response.content)

def test_correct_old_password(self):
def test_correct_current_password(self):
"""
Make sure a POST request to `change_password` works.
"""
Expand All @@ -471,14 +471,14 @@ def test_correct_old_password(self):
"/change-password/",
cookies={"id": f"{response.cookies.values()[0]}"},
json={
"old_password": f"{self.credentials['password']}",
"current_password": f"{self.credentials['password']}",
"new_password": "newpass123",
"confirm_new_password": "newpass123",
},
)
self.assertEqual(response.status_code, 303)

def test_wrong_old_password(self):
def test_wrong_current_password(self):
"""
Make sure a POST request to `change_password` works.
"""
Expand All @@ -493,7 +493,7 @@ def test_wrong_old_password(self):
"/change-password/",
cookies={"id": f"{response.cookies.values()[0]}"},
json={
"old_password": "bob1234",
"current_password": "bob1234",
"new_password": "newpass123",
"confirm_new_password": "newpass123",
},
Expand All @@ -516,7 +516,7 @@ def test_change_password_success(self):
"/change-password/",
cookies={"id": f"{response.cookies.values()[0]}"},
json={
"old_password": f"{self.credentials['password']}",
"current_password": f"{self.credentials['password']}",
"new_password": "newpass123",
"confirm_new_password": "newpass123",
},
Expand Down Expand Up @@ -560,7 +560,7 @@ def test_change_password_length(self):
"/change-password/",
cookies={"id": f"{response.cookies.values()[0]}"},
json={
"old_password": f"{self.credentials['password']}",
"current_password": f"{self.credentials['password']}",
"new_password": "john",
"confirm_new_password": "john123",
},
Expand All @@ -585,7 +585,7 @@ def test_change_password_match(self):
"/change-password/",
cookies={"id": f"{response.cookies.values()[0]}"},
json={
"old_password": f"{self.credentials['password']}",
"current_password": f"{self.credentials['password']}",
"new_password": "john123",
"confirm_new_password": "john1234",
},
Expand Down

0 comments on commit eeea268

Please sign in to comment.