Add admin user initialization script
Create init_admin.py script to properly initialize the admin user with correct password hash for "admin123". Usage: python init_admin.py This script: - Creates admin user if it doesn't exist - Uses proper bcrypt password hashing - Stores user data in data/users.yaml (gitignored) - Provides clear feedback about user creation Credentials created: - Username: admin - Password: admin123 - Role: administrator Note: data/users.yaml is gitignored (correct for user data), so admin user must be initialized on each installation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Executable
+41
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Initialize admin user for Reklamator"""
|
||||
import os
|
||||
from app import create_app
|
||||
from app.models.user import User
|
||||
|
||||
|
||||
def init_admin():
|
||||
"""Create initial admin user if it doesn't exist"""
|
||||
app = create_app('development')
|
||||
|
||||
with app.app_context():
|
||||
# Check if admin user already exists
|
||||
existing_admin = User.get_by_username('admin')
|
||||
|
||||
if existing_admin:
|
||||
print("✓ Admin user already exists")
|
||||
print(f" Username: admin")
|
||||
print(f" Email: {existing_admin.email}")
|
||||
return
|
||||
|
||||
# Create admin user
|
||||
admin = User.create(
|
||||
username='admin',
|
||||
email='admin@reklamator.local',
|
||||
password='admin123',
|
||||
role='administrator',
|
||||
product_ids=[]
|
||||
)
|
||||
|
||||
print("✓ Admin user created successfully!")
|
||||
print(f" Username: admin")
|
||||
print(f" Password: admin123")
|
||||
print(f" Email: {admin.email}")
|
||||
print(f" User ID: {admin.user_id}")
|
||||
print("")
|
||||
print("⚠️ IMPORTANT: Change the password in production!")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
init_admin()
|
||||
Reference in New Issue
Block a user