Skip to content

Commit

Permalink
continue on database is up saga
Browse files Browse the repository at this point in the history
  • Loading branch information
maggi373 committed Sep 5, 2024
1 parent 79e501d commit abf4705
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
9 changes: 4 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
from asetup import asetup
from asite import asite
from flask import Flask, render_template
from models.common import debug, host, port, api_only, management_only, migratetechnic, new_user
from models.database import Database
from models.common import debug, host, port, api_only, management_only, migratetechnic, new_user, DB_IS_UP

__version__ = solderpy_version

app: Flask = Flask(__name__)
if management_only == False or Database.is_setup() != 2:
if management_only == False or DB_IS_UP != 2:
app.register_blueprint(api)
if not api_only:
if migratetechnic is True or new_user is True or Database.is_setup() != 1:
if migratetechnic is True or new_user is True or DB_IS_UP != 1:
app.register_blueprint(asetup)
if Database.is_setup() == 1:
if DB_IS_UP == 1:
# Note that asite must be after setup
app.register_blueprint(alogin)
app.register_blueprint(asite)
Expand Down
8 changes: 5 additions & 3 deletions asetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@

from models.database import Database
from models.user import User
from models.common import migratetechnic, new_user
from models.common import migratetechnic, new_user, DB_IS_UP

asetup = Blueprint("asetup", __name__)

if Database.is_setup() != 2:
if DB_IS_UP != 2:
if migratetechnic is True or new_user is True:
Database.create_session_table()

@asetup.route("/setup", methods=["GET"])
def setup():
flash("Database created and user added", "success")
if Database.is_setup() == 2:
flash("An error occurred whilst trying to check database connection", "error")
return render_template("setup.html")
if Database.is_setup() == 0:
Database.create_tables()
if new_user or not User.any_user_exists():
if new_user == True or User.any_user_exists() == True:
if migratetechnic:
Database.migratetechnic_tables()
return render_template("setup.html")
Expand All @@ -40,5 +41,6 @@ def setup_creation():
return render_template("setup.html")
User.new(request.form["setupemail"], request.form["setupemail"],
request.form["setuppassword"], request.remote_addr, '1')
flash("Database created and user added", "success")
return redirect(url_for('asite.index'))
return render_template("setup.html")
4 changes: 2 additions & 2 deletions asite.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
from models.user import User
from mysql import connector
from werkzeug.utils import secure_filename
from models.common import mirror_url, debug, host, port, repo_url, R2_URL, db_name, R2_BUCKET, new_user, migratetechnic, solderpy_version, R2_REGION, R2_ENDPOINT, R2_ACCESS_KEY, R2_SECRET_KEY, UPLOAD_FOLDER, common
from models.common import mirror_url, debug, host, port, repo_url, R2_URL, db_name, R2_BUCKET, new_user, migratetechnic, solderpy_version, R2_REGION, R2_ENDPOINT, R2_ACCESS_KEY, R2_SECRET_KEY, UPLOAD_FOLDER, common, DB_IS_UP
from models.user_modpack import User_modpack

__version__ = solderpy_version

asite = Blueprint("asite", __name__)

if Database.is_setup() == 1:
if DB_IS_UP == 1:
Session.start_session_loop()

## Allowed extensions to be uploaded
Expand Down
2 changes: 2 additions & 0 deletions models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
R2_SECRET_KEY = os.getenv("R2_SECRET_KEY")
R2_BUCKET = os.getenv("R2_BUCKET")

DB_IS_UP = Database.is_setup()

class common:

@staticmethod
Expand Down
11 changes: 9 additions & 2 deletions models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,15 @@ def get_all_users() -> list:
def any_user_exists() -> bool:
conn = Database.get_connection()
cur = conn.cursor(dictionary=True)
cur.execute("SELECT * FROM users")
return cur.fetchone() is not None
try:
cur.execute("SELECT * FROM users")
check = cur.fetchone()
except:
flash("failed to check for existing users", "error")
return True
if check == None:
return False
return True

def get_allowed_packs(self):
conn = Database.get_connection()
Expand Down

0 comments on commit abf4705

Please sign in to comment.