Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the value of activate_url in django allauth?

I am using allauth and after registration the user receives an email asking them to click a link to verify their email address. I would like to change the value of this link.

I would like to change it from

http://localhost:8001/account/confirm-email/hy72ozw8b1cexuw2dsx4wwrmgzbmnyxx4clswh67tcvgyovg/

to

http://localhost:8001/index.html#/verifyEmail/hy72ozw8b1cexuw2dsx4wwrmgzbmnyxx4clswh67tcvgyovg/

How can I do this? I see that activate_url value is being used in email_confirmation_text.txt

like image 705
birdy Avatar asked Feb 11 '15 18:02

birdy


2 Answers

You don't really have to override allauth's urls.py in order to achieve this, all you need to do is specify your version of url after including allauth's urls:

from django.conf.urls import patterns, include, url
from allauth.account.views import confirm_email

urlpatterns = patterns('',
    ...
    url(r'^accounts/', include('allauth.account.urls')),
    url(r'^index.html#/verifyEmail/(?P<key>\w+)/$', confirm_email,
        name="account_confirm_email"),
    # but I would recommend changing that url:
    url(r'^verify-email/(?P<key>\w+)/$', confirm_email,
        name="account_confirm_email"),
    ...
)

Here is a nice article about URLS: Cool URIs don't change

like image 148
lehins Avatar answered Oct 17 '22 17:10

lehins


I have not used django-allauth or incorporated it into one of my projects, but just poking around in their source code tells me the following:

The send method just does a basic urlresolvers.reverse call, which means it's constructing the URL from account/urls.py as defined here.

As such, you have three options:

  1. Overwrite their urls.py which you will have to repeat each time you update the package (yuck).
  2. Raise an issue on their GitHub and see if they will add this as a configuration option rather than "hard-coding" it which they have done.
  3. Try to subclass their EmailConfirmation model, overriding their send method with something more appropriate for your project, and see if you can get it to use yours instead of theirs (no idea if this is workable or not).
like image 36
Two-Bit Alchemist Avatar answered Oct 17 '22 17:10

Two-Bit Alchemist