Fix: default user config
This commit is contained in:
@@ -60,10 +60,23 @@ def init_db():
|
||||
|
||||
c.execute("SELECT COUNT(*) FROM users")
|
||||
if c.fetchone()[0] == 0:
|
||||
h = generate_password_hash('admin123')
|
||||
c.execute("INSERT INTO users (username, password_hash, role, allowed_nodes) VALUES (?,?,?,?)",
|
||||
('admin', h, 'admin', 'all'))
|
||||
logger.info(">>> DEFAULT USER CREATED - User: admin | Pass: admin123 <<<")
|
||||
# Default value if missing config file
|
||||
def_user = "admin"
|
||||
def_pass = "admin123"
|
||||
|
||||
# Try read config.json
|
||||
try:
|
||||
with open(CONFIG_PATH, 'r') as f:
|
||||
cfg = json.load(f)
|
||||
def_user = cfg.get("web_admin", {}).get("default_user", "admin")
|
||||
def_pass = cfg.get("web_admin", {}).get("default_pass", "admin123")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
h = generate_password_hash(def_pass)
|
||||
c.execute("INSERT INTO users (username, password_hash, role, allowed_nodes) VALUES (?,?,?,?)",
|
||||
(def_user, h, 'admin', 'all'))
|
||||
logger.info(f">>> DEFAULT USER CREATED - User: {def_user} | Pass: {def_pass} <<<")
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
Reference in New Issue
Block a user