aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Chris Lovering <[email protected]>2024-09-13 19:06:42 +0100
committerGravatar Chris Lovering <[email protected]>2024-09-13 19:06:42 +0100
commit7968d213876aa9ade34ce056634a105381c12860 (patch)
treeade29c925ed30b2e64bfbc573502b78f5ca64687
parentAdd card wrapper around cart status on store page (diff)
Fix seed script user creation
-rw-r--r--thallium-backend/scripts/seed.py36
1 files changed, 32 insertions, 4 deletions
diff --git a/thallium-backend/scripts/seed.py b/thallium-backend/scripts/seed.py
index 0b17a4b..95d8df5 100644
--- a/thallium-backend/scripts/seed.py
+++ b/thallium-backend/scripts/seed.py
@@ -1,5 +1,7 @@
import asyncio
+from datetime import UTC, datetime
+import argon2
from sqlalchemy.dialects.postgresql import insert
from sqlalchemy.ext.asyncio import AsyncSession
@@ -7,6 +9,8 @@ from src.dto import UserPermission
from src.orm import User, Voucher
from src.settings import Connections
+ph = argon2.PasswordHasher()
+
async def create_vouchers(session: AsyncSession) -> None:
"""Create some test vouchers in the db."""
@@ -22,10 +26,34 @@ async def create_vouchers(session: AsyncSession) -> None:
async def create_users(session: AsyncSession) -> None:
"""Create some test vouchers in the db."""
entries = [
- {"permissions": UserPermission.VIEW_TEMPLATES | UserPermission.VIEW_VOUCHERS},
- {"permissions": UserPermission.MANAGE_USERS},
- {"permissions": UserPermission.ISSUE_VOUCHERS | UserPermission.REVOKE_VOUCHERS},
- {"permissions": UserPermission.UPDATE_TEMPLATES},
+ {
+ "username": "cj",
+ "password_hash": ph.hash("12345"),
+ "permissions": UserPermission.VIEW_TEMPLATES | UserPermission.VIEW_VOUCHERS,
+ "password_set_at": datetime.now(UTC),
+ "require_password_change": False,
+ },
+ {
+ "username": "joe",
+ "password_hash": ph.hash("hunter2"),
+ "permissions": UserPermission.MANAGE_USERS,
+ "password_set_at": datetime.now(UTC),
+ "require_password_change": False,
+ },
+ {
+ "username": "bella",
+ "password_hash": ph.hash("france_forever"),
+ "permissions": UserPermission.ISSUE_VOUCHERS | UserPermission.REVOKE_VOUCHERS,
+ "password_set_at": datetime.now(UTC),
+ "require_password_change": False,
+ },
+ {
+ "username": "jc",
+ "password_hash": ph.hash("tor"),
+ "permissions": UserPermission.UPDATE_TEMPLATES,
+ "password_set_at": datetime.now(UTC),
+ "require_password_change": False,
+ },
]
stmt = insert(User).values(entries).on_conflict_do_nothing()
await session.execute(stmt)