Beispiel #1
0
 def validate(self, attrs):
     validated_data = super().validate(attrs)
     mobile = SMSClaimSerializer.check_sms_token(validated_data['sms_token'])['mobile']
     SMSClaimSerializer.clear_sms_token(validated_data['sms_token'])
     user = User.valid_objects.filter(mobile=mobile).first()
     validated_data['user'] = user
     return validated_data
    def validate(self, attrs):
        '''
        校验token,验重
        '''
        validated_data = super().validate(attrs)
        if not validated_data.get('sms_token', ''):
            raise ValidationError(
                {'auth_token': ['auth_token is required, like "sms_token"']})

        username = validated_data['username']
        if User.valid_objects.filter(username=username).exists():
            raise ValidationError({'username': ['existed']})

        sms_token = validated_data.get('sms_token', None)
        if sms_token:
            mobile = SMSClaimSerializer.check_sms_token(sms_token)['mobile']
            SMSClaimSerializer.clear_sms_token(sms_token)
            validated_data['mobile'] = mobile
        return validated_data