-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_admin.py
More file actions
33 lines (32 loc) · 1.27 KB
/
Copy pathcreate_admin.py
File metadata and controls
33 lines (32 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""Run once: python create_admin.py"""
import sys, os
sys.path.insert(0, os.path.dirname(__file__))
from app import create_app
from app.models.db import execute_commit, execute_query
from werkzeug.security import generate_password_hash
app = create_app()
with app.app_context():
print("="*45)
print(" IntelliGST — Create Admin Account")
print("="*45)
u = input("Username [admin]: ").strip() or "admin"
e = input("Email [admin@intelligst.com]: ").strip() or "admin@intelligst.com"
p = input("Password [Admin@123]: ").strip() or "Admin@123"
try:
# Check if user already exists
existing = execute_query(
"SELECT user_id FROM users WHERE username=%s OR email=%s",
(u, e), fetch="one"
)
if existing:
print(f"\n⚠️ User '{u}' already exists! Login with those credentials.")
else:
hashed = generate_password_hash(p)
execute_commit(
"INSERT INTO users (username, email, password_hash, role) VALUES (%s,%s,%s,%s)",
(u, e, hashed, "admin")
)
print(f"\n✅ Admin '{u}' created successfully!")
print(f" Login at: http://localhost:5000")
except Exception as ex:
print(f"\n❌ Error: {ex}")