-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate_admin.py
More file actions
61 lines (51 loc) · 1.65 KB
/
create_admin.py
File metadata and controls
61 lines (51 loc) · 1.65 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Script to create an admin user in the database.
Usage: python3 create_admin.py
"""
import os
import sys
import getpass
from harvest_store import create_admin_user, init_db
# Import configuration
try:
from config import DB_PATH
except ImportError:
# Fallback to environment variable if config.py doesn't exist
DB_PATH = os.environ.get("HARVEST_DB", "harvest.db")
def main():
print("=== Create Admin User ===\n")
# Ensure database exists
if not os.path.exists(DB_PATH):
print(f"Database {DB_PATH} does not exist. Creating...")
init_db(DB_PATH)
print(f"✓ Created database: {DB_PATH}\n")
else:
print(f"Using existing database: {DB_PATH}\n")
# Get admin email
email = input("Admin email: ").strip()
if not email:
print("Error: Email cannot be empty")
sys.exit(1)
# Get password (hidden input)
password = getpass.getpass("Admin password: ")
if not password:
print("Error: Password cannot be empty")
sys.exit(1)
# Confirm password
password_confirm = getpass.getpass("Confirm password: ")
if password != password_confirm:
print("Error: Passwords do not match")
sys.exit(1)
# Create admin user
print("\nCreating admin user...")
success = create_admin_user(DB_PATH, email, password)
if success:
print(f"✓ Admin user created successfully: {email}")
print("\nYou can now login to the Admin panel with these credentials.")
else:
print("✗ Failed to create admin user")
sys.exit(1)
if __name__ == "__main__":
main()