diff --git a/Machine-Backend/seed_user.py b/Machine-Backend/seed_user.py new file mode 100644 index 0000000..8d0ab49 --- /dev/null +++ b/Machine-Backend/seed_user.py @@ -0,0 +1,52 @@ +from app import create_app, db +from app.models import User +import sys + +def seed_sample_user(): + """Create a sample user for testing login""" + 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 + + # 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' + ) + + # Set password + sample_user.set_password('admin123') + + # Add to database + db.session.add(sample_user) + 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) + + except Exception as e: + db.session.rollback() + print(f"❌ Error creating sample user: {str(e)}") + sys.exit(1) + +if __name__ == '__main__': + seed_sample_user() \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index a53b9ec..d3558b3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,6 +24,8 @@ services: depends_on: - db restart: always + command: > + sh -c "python seed_user.py && gunicorn --bind 0.0.0.0:5000 run:app" db: image: mysql:8.0