def set_password(self, request, pk=None):
"""Detail ``POST`` endpoint for changing a user's password
Args:
request (rest_framework.request.Request)
pk (str): primary key for user to retrieve user from database
Returns:
Response
"""
old_password = request.data.get('oldPassword')
user = authenticate(email=PFBUser.objects.get(uuid=pk).email,
password=old_password)
if not user:
raise ValidationError({'detail': 'Unable to complete password change'})
new_password = request.data.get('newPassword')
if not new_password:
raise ValidationError({'detail': 'Unable to complete password change'})
user.set_password(new_password)
user.save()
return Response({'detail': 'Successfully changed password'},
status=status.HTTP_200_OK)
评论列表
文章目录