Skip to content

Commit

Permalink
first user setup get full permission
Browse files Browse the repository at this point in the history
  • Loading branch information
maggi373 committed Sep 5, 2024
1 parent 341fe2f commit 60ef939
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 5 additions & 2 deletions asetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
if DB_IS_UP != 2:
if migratetechnic is True or new_user is True:
Database.create_session_table()
if DB_IS_UP == 0:
Database.create_tables()
Session.start_session_loop()

@asetup.route("/setup", methods=["GET"])
def setup():
Expand All @@ -25,7 +28,7 @@ def setup():
return render_template("setup.html")
return render_template("setup.html")
else:
return redirect(url_for('app.login'))
return redirect(url_for('alogin.login'))


@asetup.route("/setup", methods=["POST"])
Expand All @@ -41,7 +44,7 @@ def setup_creation():
flash("setup failed due to missing password", "error")
return render_template("setup.html")
User.new(request.form["setupemail"], request.form["setupemail"],
request.form["setuppassword"], request.remote_addr, '1')
request.form["setuppassword"], request.remote_addr, '1', True)
flash("user added", "success")
return redirect(url_for('alogin.login'))
return render_template("setup.html")
10 changes: 5 additions & 5 deletions models/user.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime

from flask import flash
from models.common import new_user
from models.common import DB_IS_UP, new_user

from .database import Database
from .modpack import Modpack
Expand All @@ -23,7 +23,7 @@ def __init__(self, id, username, email, hash, created_ip, last_ip, created_at, u
self.updated_by_user_id = updated_by_user_id

@classmethod
def new(cls, username, email, hash1, ip, creator_id):
def new(cls, username, email, hash1, ip, creator_id, setup=False):
conn = Database.get_connection()
cur = conn.cursor(dictionary=True)
now = datetime.datetime.now()
Expand All @@ -34,10 +34,10 @@ def new(cls, username, email, hash1, ip, creator_id):
conn.commit()
cur.execute("SELECT LAST_INSERT_ID() AS id")
id = cur.fetchone()["id"]
if new_user is False:
cur.execute("INSERT INTO user_permissions (user_id) VALUES (%s)", (id,))
if new_user is True:
if new_user is True or setup == True and DB_IS_UP == 0:
cur.execute("INSERT INTO user_permissions (user_id, solder_full, solder_users, solder_keys, solder_clients, solder_env, mods_create, mods_manage, mods_delete, modpacks_create, modpacks_manage, modpacks_delete) VALUES (%s, 1, 1, 1, 1, 1, 1, 1, 1 ,1 ,1 ,1)", (id,))
else:
cur.execute("INSERT INTO user_permissions (user_id) VALUES (%s)", (id,))
conn.commit()
return cls(id, username, email, password, ip, ip, now, now, ip, creator_id, creator_id)

Expand Down

0 comments on commit 60ef939

Please sign in to comment.