Skip to content

Commit 05e7a2f

Browse files
authored
Merge pull request #322 from Mosquito-Alert/api_change_password_204
Return 204 instead of 200 on password change
2 parents 3a699c2 + 924d6e7 commit 05e7a2f

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

api/auth/views.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,15 @@ class PasswordChangeView(generics.CreateAPIView):
2727
@extend_schema(
2828
operation_id='auth_change_password',
2929
responses={
30-
200: PasswordChangeSerializer,
30+
204: PasswordChangeSerializer,
3131
}
3232
)
3333
def post(self, request, format=None):
3434
user = request.user
3535
serializer = self.serializer_class(data=request.data)
3636

37-
if serializer.is_valid():
37+
if serializer.is_valid(raise_exception=True):
3838
user.set_password(serializer.validated_data['password'])
3939
user.save()
4040

41-
content = {'success': 'Password changed.'}
42-
return Response(content, status=status.HTTP_200_OK)
43-
44-
else:
45-
return Response(
46-
serializer.errors,
47-
status=status.HTTP_400_BAD_REQUEST
48-
)
41+
return Response(status=status.HTTP_204_NO_CONTENT)

api/tests/integration/auth/change_password.tavern.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ stages:
5252
json:
5353
password: newpassword
5454
response:
55-
status_code: 200
55+
status_code: 204
5656
- name: Check password has changed
5757
request:
5858
url: "{api_live_url}/auth/token/"

0 commit comments

Comments
 (0)