Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

53 linhas
1.4 KiB

  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 EncryptedPasswordProfileSerializer(serializers.ModelSerializer):
  26. class Meta:
  27. model = models.EncryptedPasswordProfile
  28. fields = (
  29. "id",
  30. "password_profile",
  31. "created",
  32. "modified",
  33. )
  34. read_only_fields = ("created", "modified")
  35. def create(self, validated_data):
  36. user = self.context["request"].user
  37. return models.EncryptedPasswordProfile.objects.create(
  38. user=user, **validated_data
  39. )
  40. class BackwardCompatibleTokenObtainPairSerializer(TokenObtainPairSerializer):
  41. def validate(self, attrs):
  42. data = super().validate(attrs)
  43. data.update({"token": data["access"]})
  44. return data