from nicegui import ui from services.auth_service import AuthService class LoginPage: def __init__(self, auth_service: AuthService): self.auth_service = auth_service def render(self): """Render login page""" with ui.column().classes('min-h-screen bg-gradient-to-br from-green-400 to-green-600 justify-center items-center'): with ui.card().classes('w-full max-w-md p-8 shadow-2xl'): ui.label('Simple Mensa Admin').classes('text-2xl font-bold text-center text-gray-800 mb-6') with ui.column().classes('space-y-4 w-full'): username_input = ui.input('Username', placeholder='Inserisci username').classes('w-full') password_input = ui.input('Password', placeholder='Inserisci password', password=True).classes('w-full') login_btn = ui.button('Accedi', on_click=lambda: self._handle_login(username_input.value, password_input.value)).classes('w-full bg-green-600 hover:bg-green-700') ui.label('Demo: admin / admin').classes('text-sm text-gray-500 text-center mt-4') def _handle_login(self, username: str, password: str): """Handle login attempt""" if not username or not password: ui.notify('Inserisci username e password', type='negative') return if self.auth_service.login(username, password): ui.notify('Login effettuato con successo', type='positive') ui.navigate.to('/') else: ui.notify('Credenziali non valide', type='negative')