How do I use emails instead of username for authentication using django-registration.
Further how do I enforce this change once I have already installed the registration module.
Do I edit the solution here Anyone knows a good hack to make django-registration use emails as usernames? in the lib folder?
The simplest way would be to hide the username field in the registration_form template with CSS display:none property. And add a script which takes the value from the email form field and sets the value in the hidden username field. So while submitting the form, the user submits the email as username without knowing it. The only problem is since a username field, by default, cannot accept an email which is longer than 30 characters. So, for safe bet, you should increase the username length manually in your database.
Here is the new registration_form.html template:
The Simple jQuery srcipt that sets the value in the hidden form field username is:
The ids id_email and id_username are set by the django-registration form automatically.
For Django >= 1.3 and < 1.5 there's Django email as username on github.
Recently I'm using registration and I switch easily to django-registration-email. It works fine on Django 1.4, reusing the same templates and simply adding
REGISTRATION_EMAIL_ACTIVATE_SUCCESS_URL = "/profiles/create/"
to redirect to the profile creation page.Django 1.5 overcome this issue through custom User model where you can specify what field is used as username. As stated in Django 1.5 documentation:
Dear fellow Django Coder,
I think this is the best way to do it. Good luck!
First step, is to create the form you'd like to use.
project/accounts/forms.py
Here you are creating a file to override the register() function in django-registration.
project/accounts/regbackend.py
Direct your urls to paths you want to use.
project/urls.py
Tell your urls to use the custom backend for the registration view. Also, import the form you created and add it to the url to be processed by the view.
project/accounts/urls.py
Hope that works!
-Matt