[Django]-Use email as username with django-registration

2👍

I think things will be easier in the long run if you keep using the default user profile. If you are only trying to add the ability to log in with an email address, I recommend creating a new authentication backend:

from django.contrib.auth.backends import ModelBackend
from django.contrib.auth.models import User


class EmailModelBackend(ModelBackend):
    def authenticate(self, username=None, password=None):
        try:
            user = User.objects.get(email__iexact=username)
            if user.check_password(password):
                return user
        except User.DoesNotExist:
            return None

You would then need to that backend to your settings.py:

AUTHENTICATION_BACKENDS = (
    'yourproject.yourapp.yourmodule.EmailModelBackend',
    'django.contrib.auth.backends.ModelBackend'
)

1👍

As-is, it’s complicated. You need to:

  • apply this patch because in d-r-1.0, models.py assumes your User model has a “username” field
  • create your own “backend” by copy/pasting/editing registration/backends/default/views.py
  • copy/paste/edit the registration form as well from registration/forms.py
  • most of the time you can use the registration views without modification

The question is about custom User and Django 1.5, so i think django-registration-email is a bad answer. Thisi is for Django <1.5, creating fake usernames and turning around the problem.

👤orzel

0👍

This might help you out:

https://pypi.python.org/pypi/django-registration-email/0.5.1

They’ve implemented this in django-registration

👤Jay

Leave a comment