From 1c2a66ddd9da8d7b01c3768d3d89c75d0fe299b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Barrag=C3=A1n=20Merino?= Date: Thu, 12 Jun 2014 12:02:16 +0200 Subject: [PATCH] Make login with the username or email --- taiga/users/services.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/taiga/users/services.py b/taiga/users/services.py index decae640..a8349c58 100644 --- a/taiga/users/services.py +++ b/taiga/users/services.py @@ -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 import Q + from taiga.base import exceptions as exc 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. 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") - qs = user_model.objects.filter(username=username) + qs = user_model.objects.filter(Q(username=username) | + Q(email=username)) if len(qs) == 0: raise exc.WrongArguments("Username or password does not matches user.")