This commit is contained in:
Iliyan Angelov
2025-12-01 15:34:45 +02:00
parent 49181cf48c
commit f7d6f24e49
28 changed files with 2121 additions and 832 deletions

View File

@@ -0,0 +1,81 @@
#!/usr/bin/env python3
"""
Script to add a housekeeping user to the database.
"""
import sys
import os
from pathlib import Path
# Add the Backend directory to the path
backend_dir = Path(__file__).parent.parent
sys.path.insert(0, str(backend_dir))
from src.shared.config.database import SessionLocal
from src.models import Role, User
import bcrypt
def add_housekeeping_user():
"""Add the housekeeping user to the database if it doesn't exist."""
db = SessionLocal()
try:
# Get housekeeping role
housekeeping_role = db.query(Role).filter(Role.name == 'housekeeping').first()
if not housekeeping_role:
print("✗ Housekeeping role not found! Please run add_housekeeping_role.py first.")
sys.exit(1)
# Check if user already exists
existing_user = db.query(User).filter(User.email == 'housekeeping@gnxsoft.com').first()
if existing_user:
print("✓ Housekeeping user already exists in the database.")
print(f" User ID: {existing_user.id}")
print(f" Email: {existing_user.email}")
print(f" Full Name: {existing_user.full_name}")
print(f" Role: {existing_user.role.name if existing_user.role else 'N/A'}")
return
# Hash password
password = 'P4eli240453.'
password_bytes = password.encode('utf-8')
salt = bcrypt.gensalt()
hashed_password = bcrypt.hashpw(password_bytes, salt).decode('utf-8')
# Create the housekeeping user
housekeeping_user = User(
email='housekeeping@gnxsoft.com',
password=hashed_password,
full_name='Housekeeping Staff',
role_id=housekeeping_role.id,
is_active=True,
currency='EUR'
)
db.add(housekeeping_user)
db.commit()
db.refresh(housekeeping_user)
print("✓ Housekeeping user created successfully!")
print(f" User ID: {housekeeping_user.id}")
print(f" Email: {housekeeping_user.email}")
print(f" Full Name: {housekeeping_user.full_name}")
print(f" Role: {housekeeping_role.name}")
print(f" Password: P4eli240453.")
except Exception as e:
db.rollback()
print(f"✗ Error creating housekeeping user: {e}")
import traceback
traceback.print_exc()
sys.exit(1)
finally:
db.close()
if __name__ == '__main__':
print("Adding housekeeping user to the database...")
print("=" * 60)
add_housekeeping_user()
print("=" * 60)
print("Done!")