auth via DB

This commit is contained in:
JiriUhlir
2026-05-28 11:40:49 +02:00
parent db039e5988
commit 09c742fefb
11 changed files with 335 additions and 23 deletions
+1
View File
@@ -0,0 +1 @@
+54
View File
@@ -0,0 +1,54 @@
import sys
from app.auth import hash_password
from app.db.database import get_connection
def main() -> int:
if len(sys.argv) != 2:
print("Použití: python -m app.scripts.set_admin_password <password>")
return 2
password_hash = hash_password(sys.argv[1])
con = get_connection()
row = con.execute("SELECT id FROM users WHERE username = ?", ("admin",)).fetchone()
if row:
con.execute(
"""
UPDATE users
SET password_hash = ?,
is_active = 1,
updated_at = CURRENT_TIMESTAMP
WHERE username = ?
""",
(password_hash, "admin"),
)
else:
con.execute(
"""
INSERT INTO users (
username,
display_name,
email,
password_hash,
role,
is_active,
created_at,
updated_at
)
VALUES (?, ?, ?, ?, ?, 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
""",
("admin", "Admin", "", password_hash, "admin"),
)
con.commit()
con.close()
print("Heslo administrátora bylo nastaveno.")
return 0
if __name__ == "__main__":
raise SystemExit(main())