change login
This commit is contained in:
@@ -26,35 +26,58 @@ class Login:
|
|||||||
self.error_message.update()
|
self.error_message.update()
|
||||||
return
|
return
|
||||||
|
|
||||||
# self.auth.placeholder.content.clean()
|
|
||||||
# two_factor = TwoFactorAuth(self.page, email, self, self.auth)
|
|
||||||
# self.auth.placeholder.content = two_factor.build()
|
|
||||||
# self.auth.placeholder.update()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# Call login endpoint
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
f"{API_BASE_URL}/auth/login",
|
f"{API_BASE_URL}/auth/login",
|
||||||
json={"email": email, "password": password},
|
json={"email": email, "password": password},
|
||||||
timeout=10
|
timeout=15,
|
||||||
)
|
)
|
||||||
|
|
||||||
if response.status_code == 200:
|
# Attempt to parse JSON safely
|
||||||
user_info = requests.get(
|
resp_ct = response.headers.get("content-type", "")
|
||||||
f"{API_BASE_URL}/auth/me",
|
resp_json = None
|
||||||
headers={"Authorization": f"Bearer {response.json().get('access_token', '')}"}
|
if "application/json" in resp_ct.lower():
|
||||||
)
|
try:
|
||||||
if user_info.status_code == 200:
|
resp_json = response.json()
|
||||||
logo_filename = user_info.json().get("logo_filename", "")
|
except Exception:
|
||||||
if logo_filename:
|
resp_json = None
|
||||||
self.page.client_storage.set("custom_logo", logo_filename)
|
|
||||||
|
|
||||||
|
if response.status_code == 200 and resp_json is not None:
|
||||||
|
access_token = resp_json.get("access_token", "")
|
||||||
|
# Fetch user info (best-effort)
|
||||||
|
ui = requests.get(
|
||||||
|
f"{API_BASE_URL}/auth/me",
|
||||||
|
headers={"Authorization": f"Bearer {access_token}"},
|
||||||
|
timeout=10,
|
||||||
|
)
|
||||||
|
|
||||||
|
if ui.status_code == 200:
|
||||||
|
try:
|
||||||
|
uj = ui.json()
|
||||||
|
logo_filename = uj.get("logo_filename", "")
|
||||||
|
if logo_filename:
|
||||||
|
self.page.client_storage.set("custom_logo", logo_filename)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Proceed to 2FA
|
||||||
self.auth.placeholder.content.clean()
|
self.auth.placeholder.content.clean()
|
||||||
two_factor = TwoFactorAuth(self.page, email, self, self.auth)
|
two_factor = TwoFactorAuth(self.page, email, self, self.auth)
|
||||||
self.auth.placeholder.content = two_factor.build()
|
self.auth.placeholder.content = two_factor.build()
|
||||||
self.auth.placeholder.update()
|
self.auth.placeholder.update()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.error_message.value = response.json().get("error", "Login failed")
|
# Build readable error message
|
||||||
|
err_msg = None
|
||||||
|
if resp_json and isinstance(resp_json, dict):
|
||||||
|
err_msg = resp_json.get("error") or resp_json.get("message")
|
||||||
|
if not err_msg:
|
||||||
|
# fallback to raw text / status code
|
||||||
|
t = response.text.strip()
|
||||||
|
err_msg = t if t else f"HTTP {response.status_code} from server"
|
||||||
|
|
||||||
|
self.error_message.value = f"Login failed: {err_msg}"
|
||||||
self.error_message.update()
|
self.error_message.update()
|
||||||
|
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
|
|||||||
Reference in New Issue
Block a user