栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Django AllAuth - How to manually send a reset-password email?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Django AllAuth - How to manually send a reset-password email?

It’s possible. My solution implements a User model post_save signal to call
the Allauth Password reset view which will send the user the email. The first
thing to consider is to make the user email address mandatory in the admin
user create form (as explained
here). And then use this pre:

from allauth.account.views import PasswordResetViewfrom django.conf import settingsfrom django.dispatch import receiverfrom django.http import HttpRequestfrom django.middleware.csrf import get_token@receiver(models.signals.post_save, sender=settings.AUTH_USER_MODEL)def send_reset_password_email(sender, instance, created, **kwargs):    if created:        # First create a post request to pass to the view        request = HttpRequest()        request.method = 'POST'        # add the absolute url to be be included in email        if settings.DEBUG: request.meta['HTTP_HOST'] = '127.0.0.1:8000'        else: request.meta['HTTP_HOST'] = 'www.mysite.com'        # pass the post form data        request.POST = { 'email': instance.email, 'csrfmiddlewaretoken': get_token(HttpRequest())        }        PasswordResetView.as_view()(request)  # email will be sent!


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/394976.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号