Reputation: 371
When I register a new user the confirmation email sent in the email template contains the url of backend but i need to handle that in forntend. Anyone know how to edit that email template of dj_rest_auth by jazzband?
The email template is:
Hello from example.com!
You're receiving this e-mail because user Pinon has given yours as an e-mail address to connect their account.
To confirm this is correct, go to http://localhost:8000/auth/registration/account-confirm-email/Nw:1kO3gI:PQDfxEOyklUYIxpjNN_011ZxGQYPJRdNomzzOFjtXA0/
Thank you from example.com! example.com
But i need it to be like this:
Hello from example.com!
You're receiving this e-mail because user Pinon has given yours as an e-mail address to connect their account.
To confirm this is correct, go to http://localhost:3000/account-confirm-email/Nw:1kO3gI:PQDfxEOyklUYIxpjNN_011ZxGQYPJRdNomzzOFjtXA0/
Thank you from example.com! example.com
Upvotes: 1
Views: 842
Reputation: 56
django_allauth
will use your request's domain to build the URL.
You can change this behaviour, by overriding the account adapter
myapp.adapters.CustomAccountAdapter
class CustomAccountAdapter(DefaultAccountAdapter):
def get_email_confirmation_url(self, request, emailconfirmation):
"""Constructs the email confirmation (activation) url.
Note that if you have architected your system such that email
confirmations are sent outside of the request context `request`
can be `None` here.
"""
url = reverse("account_confirm_email", args=[emailconfirmation.key]) # /auth/registration/account-confirm-email/<str:key>
# ret = build_absolute_uri(request, url)
return urljoin("http://localhost:3000", url)
settings.py
ACCOUNT_ADAPTER = "myapp.adapters.CustomAccountAdapter"
Docs: https://docs.allauth.org/en/latest/account/configuration.html
Tutorial on how to set up email verification with dj-rest-auth
:
Django REST framework JWT Authentication Sign up API with email confirmation.
Upvotes: 0
Reputation: 371
Ok, this thing is handled by django_allauth package. So you have to do so as they suggested in their (django_allauth) documentation
So I have created my dir like this: templates/account/email/email_confirmation_message.txt then added this code to the file:
{% 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 your e-mail address to register an account on {{ site_domain }}.
To confirm this is correct, <a href="http://localhost:3000/auth/account/confirm/email/{{ key }}" target="_blank">Click here.</a>
{% endblocktrans %}
{% blocktrans with site_name=current_site.name site_domain=current_site.domain %}Thank you from {{ site_name }}!
{{ site_domain }}{% endblocktrans %}
{% endautoescape %}
That
{{ key }}
is the main thing to find 😉.
Upvotes: 0