from app import create_app, db
from app.models import User
from flask import request

app = create_app()
with app.app_context():
    with app.test_request_context('/auth/login', method='POST', data={'username': 'admin', 'password': 'admin123'}):
        try:
            # Simulate the login logic
            username = request.form.get('username')
            password = request.form.get('password')
            print(f"Username: {username}, Password: {password}")
            
            user = User.query.filter_by(username=username).first()
            print(f"User query successful: {user}")
            
            if user and user.check_password(password) and user.is_active:
                print("Password check passed")
            else:
                print("Password check failed")
                
        except Exception as e:
            print(f"Error during login simulation: {e}")
            import traceback
            traceback.print_exc()