fixed issue that on register_user the birthday can be set

This commit is contained in:
Tim Gröger 2021-01-23 09:31:31 +01:00
parent fe7166686d
commit 4a13d3ceb1
1 changed files with 12 additions and 3 deletions

View File

@ -7,6 +7,7 @@ from flaschengeist import logger
from flaschengeist.config import config from flaschengeist.config import config
from flaschengeist.database import db from flaschengeist.database import db
from flaschengeist.utils.hook import Hook from flaschengeist.utils.hook import Hook
from flaschengeist.utils.datetime import from_iso_format
from flaschengeist.models.user import User, Role, _PasswordReset from flaschengeist.models.user import User, Role, _PasswordReset
from flaschengeist.controller import messageController, sessionController from flaschengeist.controller import messageController, sessionController
@ -46,7 +47,9 @@ def request_reset(user: User):
logger.debug(f"New password reset request for {user.userid}") logger.debug(f"New password reset request for {user.userid}")
reset = _generate_password_reset(user) reset = _generate_password_reset(user)
subject = str(config["MESSAGES"]["password_subject"]).format(name=user.display_name, username=user.userid) subject = str(config["MESSAGES"]["password_subject"]).format(
name=user.display_name, username=user.userid
)
text = str(config["MESSAGES"]["password_text"]).format( text = str(config["MESSAGES"]["password_text"]).format(
name=user.display_name, name=user.display_name,
username=user.userid, username=user.userid,
@ -155,7 +158,9 @@ def find_user(uid_mail):
if user: if user:
update_user(user) update_user(user)
else: else:
user = current_app.config["FG_AUTH_BACKEND"].find_user(uid_mail, uid_mail if mail else None) user = current_app.config["FG_AUTH_BACKEND"].find_user(
uid_mail, uid_mail if mail else None
)
if user: if user:
db.session.add(user) db.session.add(user)
db.session.commit() db.session.commit()
@ -173,6 +178,8 @@ def register(data):
allowed_keys = User().serialize().keys() allowed_keys = User().serialize().keys()
values = {key: value for key, value in data.items() if key in allowed_keys} values = {key: value for key, value in data.items() if key in allowed_keys}
roles = values.pop("roles", []) roles = values.pop("roles", [])
if "birthday" in values:
values["birthday"] = from_iso_format(values["birthday"]).date()
user = User(**values) user = User(**values)
set_roles(user, roles) set_roles(user, roles)
@ -183,7 +190,9 @@ def register(data):
reset = _generate_password_reset(user) reset = _generate_password_reset(user)
subject = str(config["MESSAGES"]["welcome_subject"]).format(name=user.display_name, username=user.userid) subject = str(config["MESSAGES"]["welcome_subject"]).format(
name=user.display_name, username=user.userid
)
text = str(config["MESSAGES"]["welcome_text"]).format( text = str(config["MESSAGES"]["welcome_text"]).format(
name=user.display_name, name=user.display_name,
username=user.userid, username=user.userid,