From a9970bec5bbd0994a825959927ad6468c7b25312 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Thu, 14 Jan 2021 19:09:01 +0100 Subject: [PATCH] Allow mail as login name. Implemented #428 --- flaschengeist/controller/userController.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/flaschengeist/controller/userController.py b/flaschengeist/controller/userController.py index 77615ba..b359d92 100644 --- a/flaschengeist/controller/userController.py +++ b/flaschengeist/controller/userController.py @@ -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):