diff --git a/Machine-Backend/.env b/Machine-Backend/.env index 55c51c2..0608171 100644 --- a/Machine-Backend/.env +++ b/Machine-Backend/.env @@ -6,14 +6,14 @@ PAYU_MERCHANT_SALT=DusXSSjqqSMTPSpw32hlFXF6LKY2Zm3y PAYU_SUCCESS_URL=http://localhost:4200/payment-success PAYU_FAILURE_URL=http://localhost:4200/payment-failure -FLASK_ENV=production +FLASK_ENV=development MYSQL_HOST=db MYSQL_USER=vendinguser MYSQL_PASSWORD=vendingpass MYSQL_DATABASE=vending -SQLITE_DB_PATH=machines +SQLITE_DB_PATH=machines.db BREVO_SMTP_EMAIL=smukeshsn2000@gmail.com BREVO_SMTP_KEY=your-brevo-smtp-key diff --git a/Machine-Backend/app/__pycache__/__init__.cpython-313.pyc b/Machine-Backend/app/__pycache__/__init__.cpython-313.pyc index 64b6863..7d9e8df 100644 Binary files a/Machine-Backend/app/__pycache__/__init__.cpython-313.pyc and b/Machine-Backend/app/__pycache__/__init__.cpython-313.pyc differ diff --git a/Machine-Backend/app/instance/machines b/Machine-Backend/app/instance/machines new file mode 100644 index 0000000..c9e6814 Binary files /dev/null and b/Machine-Backend/app/instance/machines differ diff --git a/Machine-Backend/seed_user.py b/Machine-Backend/seed_user.py index 8d0ab49..899dac9 100644 --- a/Machine-Backend/seed_user.py +++ b/Machine-Backend/seed_user.py @@ -1,52 +1,115 @@ from app import create_app, db -from app.models import User +from app.models.models import User import sys -def seed_sample_user(): - """Create a sample user for testing login""" +def seed_sample_users(): + """Create sample users for testing login with correct roles""" app = create_app() with app.app_context(): try: - # Check if user already exists - existing_user = User.query.filter_by(email='admin@vending.com').first() - if existing_user: - print("Sample user already exists!") - print(f"Email: admin@vending.com") - print(f"Password: admin123") - return + # Sample users with correct role names (must match database roles exactly) + sample_users = [ + { + 'username': 'Super Admin', + 'email': 'superadmin@vending.com', + 'password': 'admin123', + 'role': 'SuperAdmin', # MUST MATCH DATABASE EXACTLY + 'contact': '+1234567890' + }, + { + 'username': 'Management User', + 'email': 'management@vending.com', + 'password': 'management123', + 'role': 'Management', + 'contact': '+1234567891' + }, + { + 'username': 'Admin User', + 'email': 'admin@vending.com', + 'password': 'admin123', + 'role': 'Admin', + 'contact': '+1234567892' + }, + { + 'username': 'Client User', + 'email': 'client@vending.com', + 'password': 'client123', + 'role': 'Client', + 'contact': '+1234567893' + }, + { + 'username': 'Refiller User', + 'email': 'refiller@vending.com', + 'password': 'refiller123', + 'role': 'Refiller', + 'contact': '+1234567894' + }, + { + 'username': 'Servicer User', + 'email': 'servicer@vending.com', + 'password': 'servicer123', + 'role': 'Servicer', + 'contact': '+1234567895' + } + ] - # Create sample admin user - sample_user = User( - user_id=User.generate_user_id('admin', 'admin@vending.com'), - username='Admin User', - email='admin@vending.com', - contact='+1234567890', - roles='admin', - user_status='active' - ) + print("=" * 70) + print("SEEDING SAMPLE USERS") + print("=" * 70) - # Set password - sample_user.set_password('admin123') + created_count = 0 - # Add to database - db.session.add(sample_user) + for user_data in sample_users: + # Check if user already exists + existing_user = User.query.filter_by(email=user_data['email']).first() + if existing_user: + print(f"⚠️ User {user_data['email']} already exists - skipping") + continue + + # Create new user + new_user = User( + user_id=User.generate_user_id(user_data['username'], user_data['email']), + username=user_data['username'], + email=user_data['email'], + contact=user_data['contact'], + roles=user_data['role'], # CORRECT ROLE NAME + user_status='active' + ) + + # Set password + new_user.set_password(user_data['password']) + + # Add to database + db.session.add(new_user) + created_count += 1 + + print(f"✓ User: {user_data['username']} ({user_data['role']})") + + # Commit all changes db.session.commit() - print("✅ Sample user created successfully!") - print("=" * 50) - print(f"User ID: {sample_user.user_id}") - print(f"Username: {sample_user.username}") - print(f"Email: admin@vending.com") - print(f"Password: admin123") - print(f"Role: {sample_user.roles}") - print(f"Status: {sample_user.user_status}") - print("=" * 50) + print("\n" + "=" * 70) + print(f"✓ Successfully created {created_count} sample user(s)") + print("=" * 70) + + # Display all created users + print("\nCREATED USERS - USE THESE TO LOGIN:") + print("=" * 70) + all_users = User.query.all() + for user in all_users: + print(f"\nUsername: {user.username}") + print(f"Email: {user.email}") + print(f"Role: {user.roles}") + print(f"Status: {user.user_status}") + print("-" * 70) except Exception as e: db.session.rollback() - print(f"❌ Error creating sample user: {str(e)}") + print(f"\n❌ Error creating sample users: {str(e)}") + import traceback + traceback.print_exc() sys.exit(1) if __name__ == '__main__': - seed_sample_user() \ No newline at end of file + seed_sample_users() \ No newline at end of file