Allow mail as login name. Implemented #428

This commit is contained in:
Ferdinand Thiessen 2021-01-14 19:09:01 +01:00
parent 991ffb2766
commit a9970bec5b
1 changed files with 9 additions and 3 deletions

View File

@ -10,9 +10,15 @@ from flaschengeist import logger
def login_user(username, password):
logger.info("login user {{ {} }}".format(username))
try:
user = User.query.filter(User.userid == username).one()
except NoResultFound:
mail = username.split("@")
mail = len(mail) == 2 and len(mail[0]) > 0 and len(mail[1]) > 0
query = User.userid == username
if mail:
query |= User.mail == username
user = User.query.filter(query).one_or_none()
if not user:
logger.debug("User not found in Database.")
user = User(userid=username)
db.session.add(user)
if current_app.config["FG_AUTH_BACKEND"].login(user, password):