Merge main and common apps, extract authentication functionality to new authentication app. Closes issues #179 and #180
This commit is contained in:
22
mayan/apps/authentication/auth/email_auth_backend.py
Normal file
22
mayan/apps/authentication/auth/email_auth_backend.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.backends import ModelBackend
|
||||
|
||||
|
||||
class EmailAuthBackend(ModelBackend):
|
||||
"""
|
||||
Email Authentication Backend
|
||||
|
||||
Allows a user to sign in using an email/password pair rather than
|
||||
a username/password pair.
|
||||
"""
|
||||
|
||||
def authenticate(self, email=None, password=None):
|
||||
UserModel = get_user_model()
|
||||
try:
|
||||
user = UserModel.objects.get(email=email)
|
||||
if user.check_password(password):
|
||||
return user
|
||||
except UserModel.DoesNotExist:
|
||||
# Run the default password hasher once to reduce the timing
|
||||
# difference between an existing and a non-existing user (#20760).
|
||||
UserModel().set_password(password)
|
||||
Reference in New Issue
Block a user