Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accept username OR email for logging in with django-allauth

I see django-allauth supports forcing users to login using their email address, and doesn't ask them for a username when signing up (instead generating one automatically from the email address) - https://stackoverflow.com/a/19683532/221001

Is it possible to have a user sign up, entering an email address and username manually, and then allow them to sign in using either? (e.g. there are two fields on the Login page: "username or email" and "password")

like image 391
ventolin Avatar asked Sep 25 '14 11:09

ventolin


People also ask

How do I authenticate using email and password in Django?

from django.contrib.auth import authenticate, login def my_view(request): username = request.POST['username'] password = request.POST['password'] user = authenticate(request, username=username, password=password) if user is not None: login(request, user) # Redirect to a success page. ... else: # Return an 'invalid ...

How do I log into my Django email?

In order to make our email field required in our database, we need to define a custom user model. Let's do it inside our accounts application. It's also important to make our email field unique. Then, add the AUTH_USER_MODEL variable in our settings.py to tell Django we're going to use a custom model for our users.

How does Django Allauth work?

django-allauth is an integrated set of Django applications dealing with account authentication, registration, management, and third-party (social) account authentication. It is one of the most popular authentication modules due to its ability to handle both local and social logins.


1 Answers

As Yogesh posted above, the username_email value for ACCOUNT_AUTHENTICATION_METHOD does the job.

http://django-allauth.readthedocs.org/en/latest/configuration.html

like image 146
ventolin Avatar answered Sep 28 '22 16:09

ventolin