Make login with the username or email

remotes/origin/enhancement/email-actions
David Barragán Merino 2014-06-12 12:02:16 +02:00
parent ab668d5b80
commit 1c2a66ddd9
1 changed files with 5 additions and 2 deletions

View File

@ -19,12 +19,14 @@ This model contains a domain logic for users application.
""" """
from django.db.models.loading import get_model from django.db.models.loading import get_model
from django.db.models import Q
from taiga.base import exceptions as exc from taiga.base import exceptions as exc
def get_and_validate_user(*, username:str, password:str) -> bool: def get_and_validate_user(*, username:str, password:str) -> bool:
""" """
Check if user with username exists and specified Check if user with username/email exists and specified
password matchs well with existing user password. password matchs well with existing user password.
if user is valid, user is returned else, corresponding if user is valid, user is returned else, corresponding
@ -32,7 +34,8 @@ def get_and_validate_user(*, username:str, password:str) -> bool:
""" """
user_model = get_model("users", "User") user_model = get_model("users", "User")
qs = user_model.objects.filter(username=username) qs = user_model.objects.filter(Q(username=username) |
Q(email=username))
if len(qs) == 0: if len(qs) == 0:
raise exc.WrongArguments("Username or password does not matches user.") raise exc.WrongArguments("Username or password does not matches user.")