Login with email address

66 views
Skip to first unread message

Patrick Breitenbach

unread,
Nov 4, 2015, 3:36:57 AM11/4/15
to Django users
Is there a current "best" approach or module for signup/login with an email address?

<rant>I can't believe this is not included with django. In fact, it should be the default. 80-99% of services and projects do not use usernames.</rant>

Dheerendra Rathor

unread,
Nov 4, 2015, 4:50:34 AM11/4/15
to Django users
By default emails are not unique in Django. 
There are several approaches you can use:
1. In your login view use email to fetch user and then call authenticate for username. For signup you can use any garbage username!
2. Write custom user model (Just extend User model and change USERNAME_FIELD to email)
3. Write custom user model with no username field. Write an authentication backed also to use email for authentication
4. Use django dev version (They have upgraded username char limit to 254). 

On Wed, 4 Nov 2015 at 14:06 Patrick Breitenbach <pbreit...@gmail.com> wrote:
Is there a current "best" approach or module for signup/login with an email address?

<rant>I can't believe this is not included with django. In fact, it should be the default. 80-99% of services and projects do not use usernames.</rant>

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1bc440aa-6afb-48e1-bb1e-1ab937cb328c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chesco Igual

unread,
Nov 4, 2015, 8:45:33 AM11/4/15
to Django users
Hi Patrick,

I used emails "as usernames" many times in my projects. You can use django-authtools (https://github.com/fusionbox/django-authtools), it has an AbstractEmailUser (https://django-authtools.readthedocs.org/en/latest/intro.html#authtools.models.AbstractEmailUser). You can set your own custom User model, which inherits from AbstractEmailUser, and you will already have an Email authenticated user ready to roll :)

PD: I'm not related anyhow to the app, I just have found it very useful.

Cheers,
Chesco Igual.

victor menezes

unread,
Nov 4, 2015, 10:58:12 AM11/4/15
to Django users
I agree that it is time for django to change it (at least making the changes easier).

On my project I did create a new user model that inherit from AbstractUser
class UserManager(BaseUserManager): ...

class User(AbstractBaseUser):
email = models.EmailField(unique=True)
objects = UserManager()
USERNAME_FIELD = 'email'

I didn't have an password field because I use a third party(google identity toolkit to authenticate) but you can have one.
Here is the full models if you want a sample.

Russell Keith-Magee

unread,
Nov 5, 2015, 12:52:01 AM11/5/15
to Django Users
On Wed, Nov 4, 2015 at 11:58 PM, victor menezes <menezes...@gmail.com> wrote:
I agree that it is time for django to change it (at least making the changes easier)

I’m intrigued - exactly how much easier do you want us to make it? 

At this point, it is *literally* installing a third party app, adding that app to INSTALLED_APPS , and adding an AUTH_USER_MODEL setting to your configuration file. 

Changing the default isn’t a viable option, because changing the default user would break *every* Django project that assumes the current default User model is the one in existence - which is to say, every Django project generated to date that hasn’t deployed a custom User model. 

We’ve also had an open ticket #20824:


This would add an EmailUser as part of Django’s core. However, there are some techncial issues associated with this:


We haven’t worked out how to resolve these issues; if there are any suggestions, the idea has broad support from the core team.

Yours
Russ Magee %-)

Reply all
Reply to author
Forward
0 new messages