簡體   English   中英

在django allauth中更改電子郵件確認中的“ activate_url”

[英]Change “activate_url” in email confirmation in django allauth

電子郵件是從模板email_confirmation_message.txt發送的

{% load account %}{% user_display user as user_display %}{% load i18n %}{% autoescape off %}{% blocktrans with site_name=current_site.name site_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 {{ activate_url }}
{% endblocktrans %}{% endautoescape %}
{% blocktrans with site_name=current_site.name site_domain=current_site.domain %}Thank you from {{ site_name }}!
{{ site_domain }}{% endblocktrans %}

Activate_url將以http:// web / en / accounts / confirm-email / Mjc:1fWFRw:q-ScRb0Wnsrrem9N7pB9iLOuPOM /發送鏈接,其中web是我的conatiner主機名。 如何將其更改為自定義域名,而不必更改我的conatiner主機名。 我正在使用django-allauth == 0.33.0

我認為您不必更改域名。 它使用您自己的站點域。

activate_url來自get_email_confirmation_url()

 activate_url = self.get_email_confirmation_url(
 ...


def get_email_confirmation_url(self, request, emailconfirmation):
    url = reverse(
        "account_confirm_email",
        args=[emailconfirmation.key])
    ret = build_absolute_uri(
        request,
        url)
    return ret

您可以在此處查看代碼(allauth gihtub代碼)。

它使用build_absolute_uri從allatuh.utils。

這是代碼。

def build_absolute_uri(request, location, protocol=None):
    from .account import app_settings as account_settings

    if request is None:
        site = Site.objects.get_current()
        bits = urlsplit(location)
        if not (bits.scheme and bits.netloc):
            uri = '{proto}://{domain}{url}'.format(
                proto=account_settings.DEFAULT_HTTP_PROTOCOL,
                domain=site.domain,
                url=location)
        else:
            uri = location
    else:
        uri = request.build_absolute_uri(location)
    # NOTE: We only force a protocol if we are instructed to do so
    # (via the `protocol` parameter, or, if the default is set to
    # HTTPS. The latter keeps compatibility with the debatable use
    # case of running your site under both HTTP and HTTPS, where one
    # would want to make sure HTTPS links end up in password reset
    # mails even while they were initiated on an HTTP password reset
    # form.
    if not protocol and account_settings.DEFAULT_HTTP_PROTOCOL == 'https':
        protocol = account_settings.DEFAULT_HTTP_PROTOCOL
    # (end NOTE)
    if protocol:
        uri = protocol + ':' + uri.partition(':')[2]
    return uri

您可以在這里找到此代碼

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM