Create bot and admin user when creating tables
This commit is contained in:
parent
b3f76ec8bf
commit
1fe1e0e9cf
21
api/app.py
21
api/app.py
@ -1,8 +1,11 @@
|
||||
import os
|
||||
|
||||
from apiflask import APIFlask
|
||||
|
||||
from dotenv import load_dotenv
|
||||
from flask_cors import CORS
|
||||
|
||||
from api.helper_functions import hash_password
|
||||
from models import *
|
||||
from api_blueprint_keyword import keyword_blueprint
|
||||
from api_blueprint_shares import shares_blueprint
|
||||
@ -35,6 +38,24 @@ def create_app():
|
||||
def init_database():
|
||||
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 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()
|
||||
|
||||
return application
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user