Merge pull request #4 from TronoSfera/codex/fix-registration-authentication-issue

Improve client registration error reporting in client UI
This commit is contained in:
TronoSfera 2026-01-19 11:30:09 +03:00 committed by GitHub
commit e71bbd5b2e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -44,7 +44,7 @@ import sys
import time import time
from dataclasses import dataclass, asdict from dataclasses import dataclass, asdict
from pathlib import Path from pathlib import Path
from typing import Dict, Optional, List from typing import Dict, Optional, List, Tuple
import requests import requests
import yaml # type: ignore import yaml # type: ignore
@ -402,7 +402,7 @@ class BackupClient:
password: str, password: str,
client_name: str, client_name: str,
monitored_paths: List[str], monitored_paths: List[str],
) -> Optional[int]: ) -> Tuple[Optional[int], Optional[str]]:
""" """
Apply a new configuration provided by the user via the web UI. Apply a new configuration provided by the user via the web UI.
@ -417,8 +417,9 @@ class BackupClient:
client_name: Humanreadable name for this client. client_name: Humanreadable name for this client.
monitored_paths: List of directory paths to back up. monitored_paths: List of directory paths to back up.
Returns: Returns:
The numeric client ID assigned by the server, or ``None`` if A tuple of (client_id, error_message). ``client_id`` is the
registration fails. numeric client ID assigned by the server on success; otherwise
``None`` and a human-readable error message are returned.
""" """
# Update attributes # Update attributes
self.server_url = server_url.strip() self.server_url = server_url.strip()
@ -439,11 +440,11 @@ class BackupClient:
self._register_client() self._register_client()
# Save state to disk # Save state to disk
self._save_state() self._save_state()
return self.state.client_id return self.state.client_id, None
except Exception as e: except Exception as e:
# Log any error; the backup loop will skip operations until configured # Log any error; the backup loop will skip operations until configured
self.send_log(level="ERROR", message=str(e)) self.send_log(level="ERROR", message=str(e))
return None return None, str(e)
def run(self) -> None: def run(self) -> None:
""" """
@ -612,7 +613,7 @@ def create_app(client: BackupClient) -> FastAPI:
# Apply configuration and attempt to register the client. apply_config # Apply configuration and attempt to register the client. apply_config
# returns the client_id if registration succeeds. # returns the client_id if registration succeeds.
client_id = client.apply_config( client_id, error_message = client.apply_config(
server_url=server_url, server_url=server_url,
username=username, username=username,
password=password, password=password,
@ -630,6 +631,7 @@ def create_app(client: BackupClient) -> FastAPI:
}, },
) )
# If registration failed, re-render the form with a generic error message # If registration failed, re-render the form with a generic error message
error_message = error_message or "Failed to authenticate or register. Please check your credentials and server address."
return templates.TemplateResponse( return templates.TemplateResponse(
"login.html", "login.html",
{ {
@ -638,7 +640,7 @@ def create_app(client: BackupClient) -> FastAPI:
"username": username, "username": username,
"client_name": client_name, "client_name": client_name,
"monitored_paths": monitored_paths, "monitored_paths": monitored_paths,
"error": "Failed to authenticate or register. Please check your credentials and server address.", "error": error_message,
}, },
) )