fix: admin space framework-level login
Browse files
app.py
CHANGED
|
@@ -471,7 +471,7 @@ with gr.Blocks(title="Cié Cié Admin", css=custom_css, theme=gr.themes.Monochro
|
|
| 471 |
# URL 參數攔截(停用中 — 改由 FastAPI /api/booking/action 處理)
|
| 472 |
# url_action_msg = gr.HTML(visible=False)
|
| 473 |
|
| 474 |
-
with gr.Group(visible=
|
| 475 |
gr.Markdown("# 🔒 老闆/管理員登入")
|
| 476 |
with gr.Row():
|
| 477 |
username_input = gr.Textbox(label="使用者名稱")
|
|
@@ -479,7 +479,7 @@ with gr.Blocks(title="Cié Cié Admin", css=custom_css, theme=gr.themes.Monochro
|
|
| 479 |
login_btn = gr.Button("登入系統", variant="primary")
|
| 480 |
error_msg = gr.Markdown("")
|
| 481 |
|
| 482 |
-
with gr.Tabs(visible=
|
| 483 |
|
| 484 |
# --- 分頁 1:訂位與通知管理 ---
|
| 485 |
with gr.TabItem("🍷 訂位與通知管理"):
|
|
@@ -584,15 +584,22 @@ with gr.Blocks(title="Cié Cié Admin", css=custom_css, theme=gr.themes.Monochro
|
|
| 584 |
# URL 參數攔截(停用中)
|
| 585 |
# demo.load(check_url_action, inputs=None, outputs=[url_action_msg, login_row])
|
| 586 |
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
).then(
|
| 590 |
-
render_booking_cards, outputs=booking_display
|
| 591 |
-
).then(
|
| 592 |
-
get_menu_items, outputs=menu_df
|
| 593 |
-
).then(
|
| 594 |
update_menu_dropdown, outputs=m_toggle_dropdown
|
| 595 |
)
|
| 596 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 597 |
if __name__ == "__main__":
|
| 598 |
-
demo.launch()
|
|
|
|
| 471 |
# URL 參數攔截(停用中 — 改由 FastAPI /api/booking/action 處理)
|
| 472 |
# url_action_msg = gr.HTML(visible=False)
|
| 473 |
|
| 474 |
+
with gr.Group(visible=False) as login_row:
|
| 475 |
gr.Markdown("# 🔒 老闆/管理員登入")
|
| 476 |
with gr.Row():
|
| 477 |
username_input = gr.Textbox(label="使用者名稱")
|
|
|
|
| 479 |
login_btn = gr.Button("登入系統", variant="primary")
|
| 480 |
error_msg = gr.Markdown("")
|
| 481 |
|
| 482 |
+
with gr.Tabs(visible=True) as admin_tabs:
|
| 483 |
|
| 484 |
# --- 分頁 1:訂位與通知管理 ---
|
| 485 |
with gr.TabItem("🍷 訂位與通知管理"):
|
|
|
|
| 584 |
# URL 參數攔截(停用中)
|
| 585 |
# demo.load(check_url_action, inputs=None, outputs=[url_action_msg, login_row])
|
| 586 |
|
| 587 |
+
# 框架層已登入,進頁面就直接載入資料(取代舊的畫面登入流程)
|
| 588 |
+
demo.load(render_booking_cards, outputs=booking_display)
|
| 589 |
+
demo.load(get_menu_items, outputs=menu_df).then(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 590 |
update_menu_dropdown, outputs=m_toggle_dropdown
|
| 591 |
)
|
| 592 |
|
| 593 |
+
def _admin_auth(username, password):
|
| 594 |
+
"""框架層登入檢查:只認 Space secrets 的 ADMIN_USER / ADMIN_PASSWORD。
|
| 595 |
+
secrets 沒設定時一律拒絕,不使用程式碼裡的寫死預設值。"""
|
| 596 |
+
import hmac
|
| 597 |
+
real_user = os.getenv("ADMIN_USER")
|
| 598 |
+
real_password = os.getenv("ADMIN_PASSWORD")
|
| 599 |
+
if not real_user or not real_password:
|
| 600 |
+
return False
|
| 601 |
+
return hmac.compare_digest(username or "", real_user) and hmac.compare_digest(password or "", real_password)
|
| 602 |
+
|
| 603 |
+
|
| 604 |
if __name__ == "__main__":
|
| 605 |
+
demo.launch(auth=_admin_auth)
|