i’am using django-otp and Django-rest-jwt my goal is I want to check if user has enable 2fa if yes I will give him the refresh and access token i would like to change my top file to not required .
class MyTokenObtainPairSerializer(TokenObtainPairSerializer):
def __init__(self,*args,**kwargs):
super().__init__(*args,**kwargs)
self.fields['otp'] = OtpField()
def validate(self, attrs: Dict[str, Any]) -> Dict[str, str]:
data = super().validate(attrs)
user_logged_in.send(sender=self.user.__class__,request=self.context['request'],user=self.user)
if self.user is None:
user_login_failed.send(sender=self.user.__class__,request=self.context['request'],user=self.user)
return data