How to login with both username AND email address in registration redux


#1

Using the information in the first book on building a web application I managed to successfully build a registration page. Yippee!

However, I can only authenticate by using the username and password. Most login pages these days only require an email address to login, however, django-registration-redux will not recognize email addresses for logins. Is there anything I can change and over ride so it will?


#2

Oh man I am actually dealing with this right now for my new hellowebbooks.com.

This is actually more of an issue with Django, not the authentication plugin.

The proper way is to set up a custom User model when the web app is first being set up. Documentation: https://docs.djangoproject.com/en/dev/topics/auth/customizing/#auth-custom-user

That said, this is WAY harder to do if the site is already set up using Django’s (and Hello Web App’s) defaults. See the note here: https://docs.djangoproject.com/en/dev/topics/auth/customizing/#changing-to-a-custom-user-model-mid-project

So if you don’t mind starting your web app over, you can do it the proper, Django way with a custom user model. For people using Hello Web App though who are completely new to Django, I still recommend the default, username-only, no email address as login, way. Up to you and how comfortable you feel!


#3

So if I built a project and did it the Django redux way and felting like changing it the regular way then I’d have to start the project over again? Is this something where I’d have to decide early which way to do it?


#4

The email-as-username is a relatively new way to do things and not the default way of doing things in Django, unfortunately.

What I did for the new Hello Web Books website (where I am in the same boat) is probably not the best, most recommended way, but it’s been working internally so far (not launched yet.) Basically I changed it so it says email (rather than username) for creating a new user, and then internally I remove the “@” and make that the username. This isn’t shown to the user, but it fulfills Django’s requirements.

Here’s an example piece of that (I think there is more to it, but this was my starting point.)

So if starting a new project, then it’s best to set it up the recommended way by Django by having a custom User model.

If you have an existing project, just accept having a regular ol’ username, or you can make updates to the code as needed so you’re storing a created username along with the customer’s email.