-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreset_users.py
More file actions
36 lines (29 loc) · 1.21 KB
/
reset_users.py
File metadata and controls
36 lines (29 loc) · 1.21 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
"""Run this script to reset and re-create the two default users."""
import asyncio
import sys
sys.path.insert(0, '.')
from backend.database.sqlite_manager import init_db, get_session_factory
from backend.auth.service import create_user, hash_password, verify_password
async def main():
await init_db()
factory = get_session_factory()
# Test password hashing
h = hash_password("admin123")
assert verify_password("admin123", h), "Hash/verify broken!"
print("Password hashing: OK")
async with factory() as db:
from sqlalchemy import delete
from backend.database.sqlite_manager import User
# Remove existing default users
await db.execute(delete(User).where(User.username.in_(["admin", "demo"])))
await db.commit()
for username, email, password, tier in [
("admin", "admin@example.com", "admin123", "admin"),
("demo", "demo@example.com", "demo123", "pro"),
]:
user = await create_user(db, username, email, password, tier)
print(f"Created user: {username} (id={user.id})")
print("\nDone. You can now login with:")
print(" admin / admin123")
print(" demo / demo123")
asyncio.run(main())