Add environment variables

This commit is contained in:
hok7z 2022-11-26 19:22:25 +02:00
parent 606c343f53
commit d04d93eb7a
7 changed files with 23 additions and 15 deletions

1
.env.dist Normal file
View File

@ -0,0 +1 @@
db_url = "sqlite:///db.db"

13
app.py
View File

@ -1,20 +1,21 @@
from flask import Flask
from os import urandom
import logging
from apps.admin import admin as blueprint_admin
from apps.auth import auth as blueprint_auth
from database.models import build_models
import logging
from config import secret_key
app = Flask(__name__)
app.secret_key = urandom(24)
app.secret_key = secret_key
app.register_blueprint(blueprint_auth)
app.register_blueprint(blueprint_admin)
if __name__ == '__main__':
from database import build_database
build_database()
logging.info("Build database models")
build_models()
app.run(host="0.0.0.0")

View File

@ -1,7 +1,7 @@
from flask import Blueprint,render_template,request,redirect,url_for,session
from werkzeug.security import check_password_hash
from database.models import WebUser
from database import WebUser
auth = Blueprint('auth',__name__)

8
config.py Normal file
View File

@ -0,0 +1,8 @@
from environs import Env
from os import urandom
env = Env()
env.read_env()
db_url = env.str("db_url")
secret_key = urandom(48)

View File

@ -1,10 +1,9 @@
from peewee import Model,CharField
from playhouse.db_url import connect
# TODO: create connection to bot database
db = connect("sqlite:///db.db")
from config import db_url
db = connect(db_url)
class WebUser(Model):
username = CharField()
@ -25,5 +24,5 @@ class WebUser(Model):
return False
def build_models():
def build_database():
db.create_tables([WebUser])

View File

View File

@ -1 +0,0 @@
from models import WebUser