Check if user already exist

This commit is contained in:
Administrator 2022-03-27 10:55:48 +02:00
parent 1fe1e0e9cf
commit 2ba8a9bd13

View File

@ -39,22 +39,24 @@ def create_app():
db.create_all() db.create_all()
if os.getenv("BOT_USER") is not None and os.getenv("BOT_PASSWORD") is not None: if os.getenv("BOT_USER") is not None and os.getenv("BOT_PASSWORD") is not None:
bot = User( if db.session.query(User).filter_by(username=os.getenv("BOT_USER")).first() is None: # Check if user already exist
username=os.getenv("BOT_USER"), bot = User(
password=hash_password(os.getenv("BOT_PASSWORD")), username=os.getenv("BOT_USER"),
admin=False password=hash_password(os.getenv("BOT_PASSWORD")),
) admin=False
db.session.add(bot) )
db.session.commit() db.session.add(bot)
db.session.commit()
if os.getenv("ADMIN_USER") is not None and os.getenv("ADMIN_PASSWORD") is not None: if os.getenv("ADMIN_USER") is not None and os.getenv("ADMIN_PASSWORD") is not None:
admin = User( if db.session.query(User).filter_by(username=os.getenv("ADMIN_USER")).first() is None: # Check if user already exist
username=os.getenv("ADMIN_USER"), admin = User(
password=hash_password(os.getenv("ADMIN_PASSWORD")), username=os.getenv("ADMIN_USER"),
admin=True password=hash_password(os.getenv("ADMIN_PASSWORD")),
) admin=True
db.session.add(admin) )
db.session.commit() db.session.add(admin)
db.session.commit()
return application return application