Beispiel #1
0
 def validate(self, attrs):
     username = attrs["username"]
     email = attrs["email"]
     phone = attrs["phone"]
     if not re.search('({})'.format('*'), email):
         raise serializers.ValidationError("邮箱填写错误,只允许{}后缀的邮箱".format('*'))
     if not is_valid_mobile_phone(phone):
         raise serializers.ValidationError("手机号非法")
     if User.objects.filter(email=email).exclude(username=username).count():
         raise serializers.ValidationError("邮箱已经存在")
     return attrs
Beispiel #2
0
 def validate(self, attrs):
     phone = attrs["phone"]
     sms_code = attrs["sms_code"]
     # 号码是否合法
     if not is_valid_mobile_phone(phone):
         raise serializers.ValidationError("手机号非法")
     # 是否注册
     if not User.objects.filter(phone=phone).count():
         raise serializers.ValidationError("手机号未注册")
     # 验证码
     if not cache.get(phone): raise serializers.ValidationError("验证码已过期")
     if sms_code != cache.get(phone): serializers.ValidationError("验证码错误")
     return attrs
Beispiel #3
0
 def validate(self, attrs):
     email = attrs["email"]
     phone = attrs["phone"]
     sms_code = attrs["sms_code"]
     if not re.search('({})'.format('*'), email):
         raise serializers.ValidationError("邮箱填写错误,只允许{}后缀的邮箱".format('*'))
     if not is_valid_mobile_phone(phone):
         raise serializers.ValidationError("手机号非法")
     if not cache.get(phone): raise serializers.ValidationError("验证码已过期")
     if sms_code != cache.get(phone): serializers.ValidationError("验证码错误")
     if User.objects.filter(email=email).count():
         raise serializers.ValidationError("邮箱已经存在")
     if User.objects.filter(phone=phone).count():
         raise serializers.ValidationError("手机号已经存在")
     username = attrs["username"] = email.split('@')[0]
     #if User.objects.filter(username=username).count(): raise serializers.ValidationError("用户名已经存在")
     del attrs["sms_code"]
     return attrs
Beispiel #4
0
 def validate(self, attrs):
     phone = attrs["phone"]
     action = attrs["action"]
     # 号码是否合法
     if not is_valid_mobile_phone(phone):
         raise serializers.ValidationError("手机号非法")
     queryset = User.objects.filter(phone=phone)
     # 是否注册
     if action == 'register':
         if queryset.count(): raise serializers.ValidationError("手机号已经存在")
     elif action == 'login':
         if not queryset.count():
             raise serializers.ValidationError("手机号未注册")
         if queryset.filter(is_active=False):
             raise serializers.ValidationError("手机号已禁用")
     else:
         raise serializers.ValidationError("指令错误,暂时只支持指令: login、register!")
     # 发送频率
     if cache.get(phone): raise serializers.ValidationError("上一次发送的验证码未过期")
     return attrs