我有一个基本的 API 来重置密码,但是,尽管有“值”,但它似乎抛出了此错误,并没有完全出现在我的代码中:
views.py
class PasswordResetNewPasswordAPIView(GenericAPIView):
serializer_class = SetNewPasswordSerializer
def patch(self, request):
user = request.data
serializer = SetNewPasswordSerializer(data=user)
serializer.is_valid(raise_exception=True)
return Response({
"message": "password reset"},
status=status.HTTP_200_OK
)
serializers.py
class SetNewPasswordSerializer(serializers.Serializer):
password = serializers.CharField(max_length=50, write_only =True)
token = serializers.CharField(write_only =True)
uidb64 = serializers.CharField(max_length = 255, write_only =True)
fields = ("password", "token", "uidb64",)
def validate(self, attrs):
try:
password = attrs.get("password", "")
token = attrs.get("token", "")
uidb64 = attrs.get("uidb64", "")
print(uidb64)
id = force_str(urlsafe_base64_decode(uidb64))
print(id)
user = Author.objects.get(id=id)
if not PasswordResetTokenGenerator().check_token(user, token):
raise AuthenticationFailed("Invalid Reset Parameter", 401)
user.set_password(password)
user.save()
return user
except Exception:
raise AuthenticationFailed("Invalid Reset Parameter", 401)
return super().validate(attrs)
urls.py
...
path('password-reset-setup/', PasswordResetNewPasswordAPIView.as_view(),name="password-reset-setup"),
可能的错误是什么?我该如何解决它?
慕哥9229398
富国沪深
芜湖不芜
相关分类