Repository navigation
Expand file tree
/
Copy pathcreate_user_example.py
More file actions
112 lines (95 loc) · 3.12 KB
/
Copy pathcreate_user_example.py
File metadata and controls
112 lines (95 loc) · 3.12 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env python3
"""
Script to create new users in the Food Inventory Management System
Run this after starting the backend server
"""
import requests
import json
# Configuration
API_BASE_URL = "http://localhost:8000"
ADMIN_USERNAME = "admin"
ADMIN_PASSWORD = "admin123"
def login_as_admin():
"""Login as admin and get access token"""
login_data = {
"username": ADMIN_USERNAME,
"password": ADMIN_PASSWORD
}
response = requests.post(f"{API_BASE_URL}/api/auth/login", json=login_data)
if response.status_code == 200:
token_data = response.json()
return token_data["access_token"]
else:
print(f"❌ Login failed: {response.json()}")
return None
def create_user(access_token, user_data):
"""Create a new user"""
headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json"
}
response = requests.post(f"{API_BASE_URL}/api/auth/register", json=user_data, headers=headers)
if response.status_code == 201:
user = response.json()
print(f"✅ User created successfully:")
print(f" Username: {user['username']}")
print(f" Email: {user['email']}")
print(f" Role: {user['role']}")
print(f" Full Name: {user['full_name']}")
return user
else:
print(f"❌ User creation failed: {response.json()}")
return None
def main():
print("🔐 Food Inventory User Creation Tool")
print("=" * 50)
# Login as admin
print("1. Logging in as admin...")
access_token = login_as_admin()
if not access_token:
print("❌ Could not login as admin. Make sure the backend is running and admin credentials are correct.")
return
print("✅ Admin login successful!")
print()
# Example users to create
example_users = [
{
"username": "john_manager",
"email": "john@restaurant.com",
"password": "manager123",
"full_name": "John Smith",
"role": "order_maintainer"
},
{
"username": "sarah_admin",
"email": "sarah@restaurant.com",
"password": "admin456",
"full_name": "Sarah Johnson",
"role": "admin"
},
{
"username": "mike_staff",
"email": "mike@restaurant.com",
"password": "staff789",
"full_name": "Mike Wilson",
"role": "order_maintainer"
}
]
print("2. Creating example users...")
print()
for i, user_data in enumerate(example_users, 1):
print(f"Creating user {i}/3: {user_data['username']}")
create_user(access_token, user_data)
print()
print("🎉 User creation completed!")
print()
print("📋 Summary of created users:")
print("=" * 50)
for user in example_users:
print(f"Username: {user['username']}")
print(f"Password: {user['password']}")
print(f"Role: {user['role']}")
print(f"Email: {user['email']}")
print("-" * 30)
if __name__ == "__main__":
main()