Changeset - 2cb54d157d62
[Not reviewed]
default
0 3 0
Mads Kiilerich - 6 years ago 2020-03-23 14:32:06
mads@kiilerich.com
Grafted from: 1c4406f918ca
user: make get_by_username_or_email default to treat username case insensitive

The get_by_username_or_email is a flexible function, intended to find users in
multiple ways, suitable for login prompts. The function was sometimes used
with case sensitive user lookup, sometimes without. Instead, be consistent and
just default to be insensitive.
3 files changed with 2 insertions and 5 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/login.py
Show inline comments
 
@@ -82,7 +82,7 @@ class LoginController(BaseController):
 
                c.form_result = login_form.to_python(dict(request.POST))
 
                # form checks for username/password, now we're authenticated
 
                username = c.form_result['username']
 
                user = User.get_by_username_or_email(username, case_insensitive=True)
 
                user = User.get_by_username_or_email(username)
 
                assert user is not None  # the same user get just passed in the form validation
 
            except formencode.Invalid as errors:
 
                defaults = errors.value
kallithea/lib/auth_modules/__init__.py
Show inline comments
 
@@ -136,9 +136,6 @@ class KallitheaAuthPluginBase(object):
 
                  username)
 
        if username:
 
            user = User.get_by_username_or_email(username)
 
            if user is None:
 
                log.debug('Fallback to fetch user in case insensitive mode')
 
                user = User.get_by_username(username, case_insensitive=True)
 
        else:
 
            log.debug('provided username:`%s` is empty skipping...', username)
 
        return user
kallithea/model/db.py
Show inline comments
 
@@ -549,7 +549,7 @@ class User(Base, BaseDbModel):
 
        return user
 

	
 
    @classmethod
 
    def get_by_username_or_email(cls, username_or_email, case_insensitive=False, cache=False):
 
    def get_by_username_or_email(cls, username_or_email, case_insensitive=True, cache=False):
 
        """
 
        For anything that looks like an email address, look up by the email address (matching
 
        case insensitively).
0 comments (0 inline, 0 general)