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()
if os.getenv("BOT_USER") is not None and os.getenv("BOT_PASSWORD") is not None:
bot = User(
username=os.getenv("BOT_USER"),
password=hash_password(os.getenv("BOT_PASSWORD")),
admin=False
)
db.session.add(bot)
db.session.commit()
if db.session.query(User).filter_by(username=os.getenv("BOT_USER")).first() is None: # Check if user already exist
bot = User(
username=os.getenv("BOT_USER"),
password=hash_password(os.getenv("BOT_PASSWORD")),
admin=False
)
db.session.add(bot)
db.session.commit()
if os.getenv("ADMIN_USER") is not None and os.getenv("ADMIN_PASSWORD") is not None:
admin = User(
username=os.getenv("ADMIN_USER"),
password=hash_password(os.getenv("ADMIN_PASSWORD")),
admin=True
)
db.session.add(admin)
db.session.commit()
if db.session.query(User).filter_by(username=os.getenv("ADMIN_USER")).first() is None: # Check if user already exist
admin = User(
username=os.getenv("ADMIN_USER"),
password=hash_password(os.getenv("ADMIN_PASSWORD")),
admin=True
)
db.session.add(admin)
db.session.commit()
return application