- Created .gitignore to exclude virtual environment, logs, and database files. - Updated README.md with project description, features, folder structure, requirements, and usage instructions. - Implemented versioning and developer ID in agentm/__init__.py. - Developed main application logic in agentm/app.py, including credential handling and screen navigation. - Added database initialization and ROM management logic in agentm/logic/db.py and agentm/logic/db_functions.py. - Integrated DIAMBRA login functionality in agentm/logic/diambra_login.py. - Created ROM verification and caching system in agentm/logic/roms.py. - Designed user interface components for home and login screens in agentm/views/home.py and agentm/views/login.py. - Added logging utility in agentm/utils/logger.py for better debugging and tracking. - Included assets such as game images, styles, and logos. - Updated requirements.txt with necessary dependencies for the project.
69 lines
2.7 KiB
Python
69 lines
2.7 KiB
Python
from textual.screen import Screen
|
|
from textual.widgets import Input, Button, Static
|
|
from textual.containers import Vertical, Horizontal
|
|
from textual.message import Message
|
|
from textual import events
|
|
from rich.text import Text
|
|
from agentm.logic.diambra_login import login_to_diambra, save_diambra_token
|
|
from agentm.utils.logger import log_with_caller
|
|
|
|
|
|
class LoginView(Screen):
|
|
class LoginSuccess(Message):
|
|
"""Message indicating login success."""
|
|
|
|
def compose(self):
|
|
yield Vertical(
|
|
Static("🔒 Login to DIAMBRA", classes="header"),
|
|
Input(placeholder="Email", id="email_input"),
|
|
Horizontal(
|
|
Input(placeholder="Password", password=True, id="password_input"),
|
|
Button("👁", id="toggle_pw", variant="primary"),
|
|
id="pw_row"
|
|
),
|
|
Button("Login", id="login_button"),
|
|
Static("", id="status_message"),
|
|
Static(
|
|
Text.from_markup(
|
|
"Don't have an account? [bold blue link=https://old.dev.diambra.ai/register]Register here[/]"
|
|
),
|
|
id="register_link"
|
|
),
|
|
id="login_form"
|
|
)
|
|
|
|
def on_button_pressed(self, event: Button.Pressed) -> None:
|
|
if event.button.id == "toggle_pw":
|
|
password_input = self.query_one("#password_input", Input)
|
|
password_input.password = not password_input.password
|
|
password_input.refresh() # Force UI to update
|
|
return
|
|
|
|
if event.button.id == "login_button":
|
|
email_input = self.query_one("#email_input", Input)
|
|
password_input = self.query_one("#password_input", Input)
|
|
status = self.query_one("#status_message", Static)
|
|
|
|
email = email_input.value.strip()
|
|
password = password_input.value.strip()
|
|
|
|
if not email or not password:
|
|
status.update("[red]❌ Email and password required.[/red]")
|
|
return
|
|
|
|
status.update("🔐 Logging in...")
|
|
self.set_interval(0.1, lambda: self.perform_login(email, password), name="login_task")
|
|
|
|
def perform_login(self, email: str, password: str):
|
|
status = self.query_one("#status_message", Static)
|
|
|
|
try:
|
|
token = login_to_diambra(email, password)
|
|
save_diambra_token(token)
|
|
status.update("[green]✅ Login successful![/green]")
|
|
log_with_caller("info", "User logged in successfully.")
|
|
self.post_message(self.LoginSuccess())
|
|
except Exception as e:
|
|
status.update(f"[red]❌ {str(e)}[/red]")
|
|
log_with_caller("error", f"Login failed: {e}")
|