Initial commit - Customer Portal for Coolify
This commit is contained in:
1
customer_portal/scripts/__init__.py
Executable file
1
customer_portal/scripts/__init__.py
Executable file
@@ -0,0 +1 @@
|
||||
"""Portal management scripts."""
|
||||
BIN
customer_portal/scripts/__pycache__/__init__.cpython-312.pyc
Executable file
BIN
customer_portal/scripts/__pycache__/__init__.cpython-312.pyc
Executable file
Binary file not shown.
BIN
customer_portal/scripts/__pycache__/create_admin.cpython-312.pyc
Executable file
BIN
customer_portal/scripts/__pycache__/create_admin.cpython-312.pyc
Executable file
Binary file not shown.
65
customer_portal/scripts/create_admin.py
Executable file
65
customer_portal/scripts/create_admin.py
Executable file
@@ -0,0 +1,65 @@
|
||||
"""Create initial admin user.
|
||||
|
||||
Run with:
|
||||
docker exec customer_portal python -m customer_portal.scripts.create_admin
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from sqlalchemy import create_engine, text
|
||||
from werkzeug.security import generate_password_hash
|
||||
|
||||
|
||||
def create_admin():
|
||||
"""Create initial admin user if none exists."""
|
||||
database_url = os.environ.get(
|
||||
"DATABASE_URL", "postgresql://portal:portal@localhost:5432/customer_portal"
|
||||
)
|
||||
|
||||
engine = create_engine(database_url)
|
||||
|
||||
with engine.connect() as conn:
|
||||
# Check if any admin exists
|
||||
result = conn.execute(text("SELECT COUNT(*) FROM admin_users"))
|
||||
count = result.fetchone()[0]
|
||||
|
||||
if count > 0:
|
||||
print(f"Es existieren bereits {count} Admin(s).")
|
||||
result = conn.execute(text("SELECT username, name FROM admin_users"))
|
||||
for row in result:
|
||||
print(f" - {row[0]} ({row[1]})")
|
||||
return
|
||||
|
||||
# Create default admin
|
||||
username = "admin"
|
||||
password = "admin123!"
|
||||
password_hash = generate_password_hash(password)
|
||||
|
||||
conn.execute(
|
||||
text(
|
||||
"""
|
||||
INSERT INTO admin_users (username, password_hash, name, email, is_active)
|
||||
VALUES (:username, :password_hash, :name, :email, TRUE)
|
||||
"""
|
||||
),
|
||||
{
|
||||
"username": username,
|
||||
"password_hash": password_hash,
|
||||
"name": "Administrator",
|
||||
"email": "admin@example.com",
|
||||
},
|
||||
)
|
||||
conn.commit()
|
||||
|
||||
print("=" * 50)
|
||||
print("Admin-Benutzer erfolgreich erstellt!")
|
||||
print("=" * 50)
|
||||
print(f" Benutzername: {username}")
|
||||
print(f" Passwort: {password}")
|
||||
print("")
|
||||
print("WICHTIG: Aendern Sie das Passwort nach dem ersten Login!")
|
||||
print("=" * 50)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
create_admin()
|
||||
Reference in New Issue
Block a user