Esempio n. 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
Esempio n. 2
0
    def validate(self, attrs):
        validated_data = super().validate(attrs)
        old_mobile = SMSClaimSerializer.check_sms_token(validated_data.get('old_mobile_sms_token'))['mobile']
        new_mobile = SMSClaimSerializer.check_sms_token(validated_data.get('new_mobile_sms_token'))['mobile']

        request = self.context.get("request")
        user = request.user

        if user.mobile != old_mobile:
            raise ValidationError({'old_mobile': 'invalid mobile'})

        if User.valid_objects.filter(mobile=new_mobile).exists():
            raise ValidationError({'new_mobile': 'has been used'})

        validated_data.update(new_mobile=new_mobile)

        return validated_data
Esempio n. 3
0
def check_user_exists(request):
    '''
    查询用户是否注册
    '''
    sms_token = request.data.get('sms_token', '')
    if sms_token:
        mobile = SMSClaimSerializer.check_sms_token(sms_token)['mobile']
        exist = User.valid_objects.filter(mobile=mobile).exists()
    return exist
Esempio n. 4
0
 def post(self, request):  # pylint: disable=no-self-use
     '''
     查询用户是否注册
     '''
     sms_token = request.data.get('sms_token', '')
     if sms_token:
         mobile = SMSClaimSerializer.check_sms_token(sms_token)['mobile']
         exist = User.valid_objects.filter(mobile=mobile).exists()
         return Response({'exist': exist})
     raise ValidationError({'sms_token': ["sms_token invalid"]})
Esempio n. 5
0
def check_user_exists(request):
    '''
    查询用户是否注册
    '''
    sms_token = request.data.get('sms_token', None)
    if sms_token:
        mobile = SMSClaimSerializer.check_sms_token(sms_token)['mobile']
        exist = User.valid_objects.filter(mobile=mobile).exists()
        return exist
    raise ValidationError({'sms_token': ["sms_token invalid"]})
Esempio n. 6
0
    def validate(self, attrs):
        validated_data = super().validate(attrs)
        old_admin_mobile = SMSClaimSerializer.check_sms_token(validated_data.get('old_admin_sms_token'))['mobile']
        new_admin_mobile = SMSClaimSerializer.check_sms_token(validated_data.get('new_admin_sms_token'))['mobile']

        queryset = User.valid_objects.filter(
            mobile=old_admin_mobile,
            is_boss=True,
        )
        if queryset.count() != 1:
            raise ValidationError({"old_admin_sms_token": ["not valid admin"]})
        old_admin = queryset.first()

        queryset = User.valid_objects.filter(mobile=new_admin_mobile, )
        if queryset.count() != 1:
            raise ValidationError({"new_admin_sms_token": ["not valid admin"]})
        new_admin = queryset.first()

        validated_data.update(old_admin=old_admin, new_admin=new_admin)

        return validated_data
Esempio n. 7
0
    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