Revision 792fad7a snf-astakos-app/astakos/im/auth_backends.py

b/snf-astakos-app/astakos/im/auth_backends.py
32 32
# or implied, of GRNET S.A.
33 33

  
34 34
from django.contrib.auth.backends import ModelBackend
35
from django.core.validators import email_re
36 35

  
37 36
from astakos.im.models import AstakosUser
38 37
from astakos.im.settings import LOGGING_LEVEL
......
72 71
    Used from ``astakos.im.forms.LoginForm`` to authenticate.
73 72
    """
74 73
    def authenticate(self, username=None, password=None):
75
        #If username is an email address, then try to pull it up
76
        if email_re.search(username):
77
            users = AstakosUser.objects.filter(email__iexact=username)
78
            if not users:
79
                return None
80
            for user in users:
81
                if  user.check_password(password):
82
                    return user
83
        else:
84
            #We have a non-email address username we
85
            #should try username
86
            try:
87
                user = AstakosUser.objects.get(username=username)
88
            except AstakosUser.DoesNotExist:
89
                return None
74
        # First check whether a user having this email exists
75
        users = AstakosUser.objects.filter(email__iexact=username)
76
        for user in users:
77
            if  user.check_password(password):
78
                return user
79
        
80
        # Since no user has been found by email try with the username
81
        try:
82
            user = AstakosUser.objects.get(username=username)
83
        except AstakosUser.DoesNotExist:
84
            return None
85
        
90 86
        if user.check_password(password):
91 87
            return user
92 88
        else:

Also available in: Unified diff