25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

35 lines
967 B

  1. from api import models
  2. from rest_framework import serializers
  3. from rest_framework_simplejwt.serializers import TokenObtainPairSerializer
  4. class PasswordSerializer(serializers.ModelSerializer):
  5. class Meta:
  6. model = models.Password
  7. fields = (
  8. "id",
  9. "login",
  10. "site",
  11. "lowercase",
  12. "uppercase",
  13. "symbols",
  14. "numbers",
  15. "counter",
  16. "length",
  17. "version",
  18. "created",
  19. "modified",
  20. )
  21. read_only_fields = ("created", "modified")
  22. def create(self, validated_data):
  23. user = self.context["request"].user
  24. return models.Password.objects.create(user=user, **validated_data)
  25. class BackwardCompatibleTokenObtainPairSerializer(TokenObtainPairSerializer):
  26. def validate(self, attrs):
  27. data = super().validate(attrs)
  28. data.update({"token": data["access"]})
  29. return data