python - Django Rest Framework + Django-Allauth 密码重置/恢复

标签 python django django-rest-framework django-allauth password-recovery

我正在尝试使用 Django Rest Framework 和 Django-Allauth 创建密码恢复流程。

Django-Allauth 已经完成了我需要的一切,我的问题是我能否以编程方式调用 django-allauth 函数或从 DRF 查看接收到的电子邮件我想重置并继续正常的 allauth 流程的其余部分(比如创建临时 token 并将电子邮件发送给客户?

如果其中一个应用程序正在做我需要的一切,我不认为必须重写所有代码有什么意义。只需要一些关于如何“粘合”它们的帮助:)

最佳答案

我想通了

我将其添加到我的 DRF 资源中

@list_route(
    methods=['post'], permission_classes=[AllowAny],
    authentication_classes=[NoAuthentication]
)
def recover_password(self, request):
    if request.DATA.get('email'):
        # Lets be smart and reuse django-allauth password recovery system
        form = ResetPasswordForm({'email': request.DATA.get('email')})
        if form.is_valid():
            form.save()
            return Response(status=200)
    return Response(status=400)

关于python - Django Rest Framework + Django-Allauth 密码重置/恢复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26869309/

相关文章:

python - 为什么在python中编写确定 "machine precision"的程序时定义eps=1并除以2

python - flask 信号 : why is it not ok to modify data on signal?

python - 如何使用 Django 发送/获取 JSON 对象?

django - 在 django 中使用 makemigration 时出错

Django JWT 获取用户信息

python - 来自environment.yml的Conda环境-来自git的私有(private)包?

django-创建一个模型,让您为同一字段插入多个值?

Python、pinax、django、windows AttributeError : 'module' object has no attribute 'call_subprocess'

django 休息框架 : set field-level error from serializer validate() method

Django更新,没有必填字段