Ooto
Ooto

Reputation: 1257

Django all auth: How to override the confirmation email url

What I want to do is to override confirmation email url in templates/account/email/email_confirmation_message.txt.

I want to change this part

To confirm this is correct, go to {{ activate_url }}

to something like

http://localhost:8080/confirm_email/{{ key }}

However, I couldn't figure out where {{ activate_url }} comes from. I want to send the key to the endpoint made by rest-auth.

How can I rewrite the url link on email? Or if it's too complitcated, what is the easy way to verify the email on frontend?

Upvotes: 7

Views: 5379

Answers (2)

Tony Aziz
Tony Aziz

Reputation: 1067

To fix this problem u may just need to override send_email function.

from allauth.account.adapter import DefaultAccountAdapter
from django.conf import settings

class CustomAllauthAdapter(DefaultAccountAdapter):
    def send_mail(self, template_prefix, email, context):
    account_confirm_email = '/api/v1/auth/register/account-confirm-email/'
    context['activate_url'] = (
        settings.BASE_URL + account_confirm_email + context['key']
    )
    msg = self.render_mail(template_prefix, email, context)
    msg.send()

Upvotes: 4

dirkgroten
dirkgroten

Reputation: 20702

The template is rendered with a context containing user, current_site, activate_url and key (see the send_confirmation_mail() method in allauth/account/adapter.py).

So you can just override the template and use key (and probably also current_site to make an absolute URI) to create your URL in the template.

Upvotes: 6

Related Questions