import requests
from app import create_app
from app.models.user import User

# Test credentials
print("Testing login and rating flow...")
print("\nAvailable users:")
print("1. rocky.mcloughlin@gmail.com (Worker)")
print("2. mcloughlinmichael.r@gmail.com (Contractor)")

base_url = "http://localhost:5000"
session = requests.Session()

# Test login
email = input("\nEnter email to test with: ").strip()
password = input("Enter password (or press Enter to try 'password'): ").strip() or "password"

login_data = {
    'email': email,
    'password': password
}

# Attempt login
response = session.post(f"{base_url}/login", data=login_data, allow_redirects=False)
print(f"\nLogin response: {response.status_code}")

if response.status_code == 302:  # Redirect means success
    print("Login successful!")
    
    # Now try to access rating page
    rating_response = session.get(f"{base_url}/contracts/7/rate")
    print(f"Rating page access: {rating_response.status_code}")
    
    if rating_response.status_code == 200:
        print("✓ Can access rating page!")
        print("You can now rate through the web interface")
    else:
        print(f"Issue accessing rating page: {rating_response.text[:200]}")
else:
    print("Login failed. Check password or user setup.")
