Mercurial > kallithea
changeset 5689:5bd63512505e
db: add User.get_by_username_or_email
author | Andrew Shadura <andrew@shadura.me> |
---|---|
date | Sat, 30 Jan 2016 15:59:33 +0100 |
parents | 0d213881f2ca |
children | 2c3941817a8e |
files | kallithea/model/db.py |
diffstat | 1 files changed, 14 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/model/db.py Mon Feb 01 00:36:09 2016 +0100 +++ b/kallithea/model/db.py Sat Jan 30 15:59:33 2016 +0100 @@ -553,6 +553,20 @@ return user @classmethod + def get_by_username_or_email(cls, username_or_email, case_insensitive=False, cache=False): + """ + For anything that looks like an email address, look up by the email address (matching + case insensitively). + For anything else, try to look up by the user name. + + This assumes no normal username can have '@' symbol. + """ + if '@' in username_or_email: + return User.get_by_email(username_or_email, cache=cache) + else: + return User.get_by_username(username_or_email, case_insensitive=case_insensitive, cache=cache) + + @classmethod def get_by_username(cls, username, case_insensitive=False, cache=False): if case_insensitive: q = cls.query().filter(func.lower(cls.username) == func.lower(username))