Django-allauth: Unique Email: Error Message Issue

Created on 28 Jul 2016  路  5Comments  路  Source: pennersr/django-allauth

Attempt to create another account with the same email while ACCOUNT_UNIQUE_EMAIL = True renders an error message - as it should. The message however reads like "%(model_name)s mit diesem %(field_label)s existiert bereits." instead of something humanly readable.

TODO

Most helpful comment

For others who have the same issue. I fixed it like this:

I've created custom adapter like this:

from django.utils.translation import ugettext_lazy as _
from allauth.account.adapter import DefaultAccountAdapter

class CustomAccountAdapter(DefaultAccountAdapter):
    def __init__(self, request=None):
        super(CustomAccountAdapter, self).__init__(request)
        self.error_messages['email_taken'] = _('A user is already registered with this e-mail address.')

Then you put this config into your setting:
ACCOUNT_ADAPTER = 'apps.your_app.pathtothe.adapter.CustomAccountAdapter'

The thing is that DefaultAdapter checks email field uniqueness against EmailAddresses model (not against your custom user model). And if you want to customize message there then you will need to override EmailAddresses which is not convenient.

Having documentation after this kind of change would be much helpful.

All 5 comments

I have the same. And I figured out that you removed this check from clean_email method in forms.py. Any good reason for removing raise_duplicate_email_error()? Any advice to overcome this problem?

You should be careful with this kind of changes because it breaks backwards compatibility. At least you should document it.

For others who have the same issue. I fixed it like this:

I've created custom adapter like this:

from django.utils.translation import ugettext_lazy as _
from allauth.account.adapter import DefaultAccountAdapter

class CustomAccountAdapter(DefaultAccountAdapter):
    def __init__(self, request=None):
        super(CustomAccountAdapter, self).__init__(request)
        self.error_messages['email_taken'] = _('A user is already registered with this e-mail address.')

Then you put this config into your setting:
ACCOUNT_ADAPTER = 'apps.your_app.pathtothe.adapter.CustomAccountAdapter'

The thing is that DefaultAdapter checks email field uniqueness against EmailAddresses model (not against your custom user model). And if you want to customize message there then you will need to override EmailAddresses which is not convenient.

Having documentation after this kind of change would be much helpful.

Happened to me too, thanks for the workaround @bnisevic although i used CustomAccountAdapter instead of GiivxAccountAdapter

@j0hn you're welcome. Yes, sorry, I had problem with github code markup while I was writing the comment. Giivx name was leftover from my own project. I've updated the comment with CustomAccountAdapter name. Thanks for noticing!

Done (0e62e7be524168b19dd18bb617e661a61f5a63e0)

Was this page helpful?
0 / 5 - 0 ratings