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 ") 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())