Skip to content
Snippets Groups Projects
Commit 443509ca authored by Valentin Rigal's avatar Valentin Rigal Committed by Erwan Rouchet
Browse files

Update session data when updating the password with UpdateUser

parent 975b3f74
No related branches found
No related tags found
1 merge request!2326Update session data when updating the password with UpdateUser
from django.conf import settings
from django.contrib.auth import update_session_auth_hash
from django.contrib.auth.password_validation import validate_password
from django.contrib.auth.tokens import default_token_generator
from django.core.exceptions import ValidationError
......@@ -66,6 +67,7 @@ class UserSerializer(SimpleUserSerializer):
def update(self, instance, validated_data):
if "password" in validated_data:
instance.set_password(validated_data.pop("password"))
update_session_auth_hash(self.context["request"], instance)
return super().update(instance, validated_data)
......
......@@ -57,6 +57,12 @@ class TestRegistration(FixtureAPITestCase):
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.user.refresh_from_db()
self.assertTrue(self.user.check_password("N€wP4$5w0Rd"))
# Ensure client session is still valid
response = self.client.get(
reverse("api:user-retrieve"),
format="json",
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_update_display_name(self):
self.client.force_login(self.user)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment