Created
December 30, 2019 11:20
-
-
Save DenoGeek/a86b4c79024b3c89af776d2b5d42325d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MobileTokenBaseSerializer(serializers.Serializer): | |
verification_code=serializers.CharField() | |
def validate_verification_code(self,value): | |
if not MobileToken.objects.filter(verification_code=value).exists(): | |
raise serializers.ValidationError("The token provided does not exist") | |
elif MobileToken.objects.filter(verification_code=value).first().is_used: | |
raise serializers.ValidationError("The token provided is used") | |
return value | |
def validate(self, attrs): | |
m_token=MobileToken.objects.filter(verification_code=attrs["verification_code"]).first() | |
self.user = m_token.user | |
return {} | |
class MobileTokenSerializer(MobileTokenBaseSerializer): | |
@classmethod | |
def get_token(cls, user): | |
return RefreshToken.for_user(user) | |
def validate(self, attrs): | |
data = super().validate(attrs) | |
refresh = self.get_token(self.user) | |
data['refresh'] = str(refresh) | |
data['access'] = str(refresh.access_token) | |
return data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment