如何在allauth中更改电子邮件验证链接 [英] How to change the email verification link in allauth

查看:164
本文介绍了如何在allauth中更改电子邮件验证链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在django应用程序中使用allauth.创建用户后,它会发送一封电子邮件,其中包含这样的http://localhost:8001/account/confirm-email/asdfafsd/

I'm using allauth in my django application. Once the user is created it sends an email with the link like this http://localhost:8001/account/confirm-email/asdfafsd/

但是,我希望链接为http://localhost:8001/verifyEmail/asdfafsd,因为我在前端使用了角度.

However, I want the link to be http://localhost:8001/verifyEmail/asdfafsd since I am using angular on the front end.

我不知道要在哪里更改此链接?

I can't figure out where to change this link?

推荐答案

  1. 通过创建相同的命名文件来覆盖模板. 对于django-allauth:templates/account/email_confirmation_message.txt
  2. 创建一个示例自定义标签,并将其包含在您的任何应用中,即 例如userprofile/templatetags/userprofile.py

  1. Override the template by creating a same named file. For django-allauth: templates/account/email_confirmation_message.txt
  2. create a sample custom tag and include in any of your app, i.e for example app userprofile in userprofile/templatetags/userprofile.py

就像

from django import template
from django.template.defaultfilters import stringfilter

register = template.Library()



@register.simple_tag(name="make_confirm_url", takes_context=True)
def make_confirm_url(context):
    activate_url = context.get('activate_url')
    slice_idx = activate_url.find('account')
    return ''.join(['http://', context.get('current_site').domain, '/',activate_url[slice_idx:]])

  • email_confirmation_message.txt可以像

    {% load userprofile %}{% make_confirm_url as the_link %}
    {% load account %}{% user_display user as user_display %}{% load i18n %}
    {% autoescape off %}{% blocktrans with site_name=current_site.namesite_domain=current_site.domain %}
    Hello from {{ site_name }}!
    
    You're receiving this e-mail because user {{ user_display }} has given yours as an e-mail address to connect their account.
    
    To confirm this is correct, go to {{the_link}}
    {% endblocktrans %}{% endautoescape %}
    {% blocktrans with site_name=current_site.name site_domain=current_site.domain %}Thank you from {{ site_name }} Dev Team !
    {{ site_domain }}{% endblocktrans %}
    

  • 在上面的代码中,该域是从django_sites模型中获取的.您可以包括您的逻辑,并在前端框架(例如angular)中相应地编写一条路由.谢谢

  • In the above code the domain is fetched from the django_sites Model You can include you logics and write a route accordingly in frontend framework (like angular). Thanks

    这篇关于如何在allauth中更改电子邮件验证链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆