如何调用自定义的PasswordResetSerializer? (Django-DRF)

时间:2019-06-28 17:49:44

标签: django django-rest-framework django-serializer reset-password

我想使用我的自定义PasswordResetSerializer在用户达到登录尝试限制后自动发送电子邮件

此自定义序列化程序可通过API调用在前端运行良好,但我想在身份验证后端中使用它(请参见authentication.py最后一行)

这是我的代码:

authentication.py

RewriteEngine On

RewriteBase /

 RewriteRule http://127.0.0.1:3034/ [P,L]
 RewriteCond %{REQUEST_FILENAME} !-f    
 RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/(.*)$ http://127.0.0.1:3034/$1 [P,L]

这是我的自定义序列化器

serializers.py

class ExampleAuthentication(authentication.BaseAuthentication):
    def authenticate(self, request):
        username = request.data.get('email', None)  # get the username request header
        password = request.data.get('password', None)

    """
    After all validations and login attempts

    """
    if user.fails_authentication():
        #Use here my custom PasswordResetSerializer

0 个答案:

没有答案