parent
9f52d633c1
commit
f0b41d28e6
|
@ -51,6 +51,7 @@ class CaptchaView(APIView):
|
||||||
return SuccessResponse(data=json_data)
|
return SuccessResponse(data=json_data)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class LoginSerializer(TokenObtainPairSerializer):
|
class LoginSerializer(TokenObtainPairSerializer):
|
||||||
"""
|
"""
|
||||||
登录的序列化器:
|
登录的序列化器:
|
||||||
|
@ -68,7 +69,10 @@ class LoginSerializer(TokenObtainPairSerializer):
|
||||||
}
|
}
|
||||||
|
|
||||||
def validate(self, attrs):
|
def validate(self, attrs):
|
||||||
|
captcha = getattr(attrs,'captcha',None)
|
||||||
if settings.CAPTCHA_STATE:
|
if settings.CAPTCHA_STATE:
|
||||||
|
if captcha is None:
|
||||||
|
raise CustomValidationError("验证码不能为空")
|
||||||
self.image_code = CaptchaStore.objects.filter(
|
self.image_code = CaptchaStore.objects.filter(
|
||||||
id=self.initial_data['captchaKey']).first()
|
id=self.initial_data['captchaKey']).first()
|
||||||
five_minute_ago = datetime.now() - timedelta(hours=0, minutes=5, seconds=0)
|
five_minute_ago = datetime.now() - timedelta(hours=0, minutes=5, seconds=0)
|
||||||
|
@ -76,7 +80,6 @@ class LoginSerializer(TokenObtainPairSerializer):
|
||||||
self.image_code and self.image_code.delete()
|
self.image_code and self.image_code.delete()
|
||||||
raise CustomValidationError('验证码过期')
|
raise CustomValidationError('验证码过期')
|
||||||
else:
|
else:
|
||||||
captcha = attrs['captcha']
|
|
||||||
if self.image_code and (self.image_code.response == captcha or self.image_code.challenge == captcha):
|
if self.image_code and (self.image_code.response == captcha or self.image_code.challenge == captcha):
|
||||||
self.image_code and self.image_code.delete()
|
self.image_code and self.image_code.delete()
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue