I'm creating a django project for a school, and there are three main kinds of users - parents, teachers, and students. For parents and teachers, I would like them to login using email (they are currently using email logins for a legacy system).
However, for students, I would like them to login using the conventional username approach (since young kids don't have emails). Is this possible to do in Django or is there only one User Authentication model allowed?
You can create separate
AuthenticationEmailBackend
just for logging by email and add it toAUTHENTICATION_BACKENDS
in settings. In this way differentAUTHENTICATION_BACKENDS
are used as alternatives if authentication fails for previousAUTHENTICATION_BACKENDS
.app/auth.py
settings.py
If you leave default
django.contrib.auth.backends.ModelBackend
in a list users can login by either username or email.Seems request parameter is needed in authenticate method from Django 1.11:
According to what is said in Django documentation.
A simple backend which allows you to login with either an email address or a username.
It should be combined with another backend for checking permissions:
settings.py:
account/backends.py:
and for case-insensitive :