Update app.py
Browse files
app.py
CHANGED
|
@@ -156,18 +156,6 @@ def fast_login(target_account, ip, cookie, time_mode, custom_time, ow, tw, iw, d
|
|
| 156 |
|
| 157 |
return gr.update(visible=False), gr.update(visible=True), gr.update(visible=is_student), gr.update(visible=is_admin), "", welcome_msg, df, target_account
|
| 158 |
|
| 159 |
-
def switch_role(target_account, ip, cookie, time_mode, custom_time, ow, tw, iw, dw):
|
| 160 |
-
role, name = USER_DB[target_account][1], USER_DB[target_account][2]
|
| 161 |
-
df = record_log(ip, cookie, target_account, role, "login_attempt", "success", time_mode, custom_time, ow, tw, iw, dw)
|
| 162 |
-
|
| 163 |
-
welcome_msg = f"**{name}** 歡迎您 | 線上人數: 938 (⚡快速切換模式)"
|
| 164 |
-
is_student = (role == "學生")
|
| 165 |
-
is_admin = (role == "管理")
|
| 166 |
-
|
| 167 |
-
# 🌟 關鍵修改:前兩個回傳使用空的 gr.update()
|
| 168 |
-
# 告訴 Gradio:「不要重新渲染 login_view 與 dashboard_view 的外框」
|
| 169 |
-
return gr.update(), gr.update(), gr.update(visible=is_student), gr.update(visible=is_admin), "", welcome_msg, df, target_account
|
| 170 |
-
|
| 171 |
def process_login(ip, cookie, account, password, captcha, time_mode, custom_time, ow, tw, iw, dw):
|
| 172 |
valid_captcha = "FEIK"
|
| 173 |
def fail_response(msg, df):
|
|
@@ -252,10 +240,12 @@ with gr.Blocks(title="模擬校園入口與資安防護系統", css=custom_css)
|
|
| 252 |
gr.Markdown("### 資訊系統")
|
| 253 |
welcome_text = gr.Markdown(value="", elem_classes="text-right")
|
| 254 |
logout_btn = gr.Button("登出", size="sm")
|
|
|
|
|
|
|
|
|
|
| 255 |
gr.Markdown("---")
|
| 256 |
|
| 257 |
with gr.Column(visible=False) as student_view:
|
| 258 |
-
btn_switch_admin = gr.Button("🔄 快速切換為管理員 (Admin) 視角", size="sm", variant="secondary")
|
| 259 |
with gr.Accordion("▼ 1. 教務系統", open=True):
|
| 260 |
with gr.Row(): btn_eval = gr.Button("▶ 期末網路教學評量", size="sm"); btn_pre_select = gr.Button("▶ 期末網路預選系統", size="sm"); btn_add_drop = gr.Button("▶ 開學後加退選系統", size="sm")
|
| 261 |
with gr.Row(): btn_istudy = gr.Button("▶ 北科i學園PLUS", size="sm"); btn_card = gr.Button("▶ 學生證掛失及補發系統", size="sm"); btn_course = gr.Button("▶ 課程系統", size="sm")
|
|
@@ -268,7 +258,6 @@ with gr.Blocks(title="模擬校園入口與資安防護系統", css=custom_css)
|
|
| 268 |
btn_hack_score = gr.Button("💀 嘗試偷改成績 (SQL Injection)", variant="stop", size="sm")
|
| 269 |
|
| 270 |
with gr.Column(visible=False) as admin_view:
|
| 271 |
-
btn_switch_student = gr.Button("🔄 快速切換為學生 (Student) 視角", size="sm", variant="secondary")
|
| 272 |
with gr.Accordion("▼ 防護強度微調 (AI 敏感度)", open=True, elem_classes="weight-card"):
|
| 273 |
gr.Markdown("<span style='color:gray; font-size:0.9em;'>手動輸入 0~100 的數值。提高強度會增加誤報率,但能更有效攔截新型攻擊。</span>")
|
| 274 |
with gr.Row():
|
|
@@ -343,11 +332,9 @@ with gr.Blocks(title="模擬校園入口與資安防護系統", css=custom_css)
|
|
| 343 |
|
| 344 |
btn_fast_student.click(fn=lambda ip, c, tm, ct, ow, tw, iw, dw: fast_login("student", ip, c, tm, ct, ow, tw, iw, dw), inputs=fast_inputs, outputs=fast_outputs)
|
| 345 |
btn_fast_admin.click(fn=lambda ip, c, tm, ct, ow, tw, iw, dw: fast_login("admin", ip, c, tm, ct, ow, tw, iw, dw), inputs=fast_inputs, outputs=fast_outputs)
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
btn_switch_student.click(fn=lambda ip, c, tm, ct, ow, tw, iw, dw: switch_role("student", ip, c, tm, ct, ow, tw, iw, dw), inputs=fast_inputs, outputs=fast_outputs)
|
| 350 |
-
|
| 351 |
action_mapping = [
|
| 352 |
(btn_eval, "click_eval_system"), (btn_pre_select, "click_pre_select_system"),
|
| 353 |
(btn_add_drop, "click_add_drop_system"), (btn_istudy, "click_istudy"),
|
|
|
|
| 156 |
|
| 157 |
return gr.update(visible=False), gr.update(visible=True), gr.update(visible=is_student), gr.update(visible=is_admin), "", welcome_msg, df, target_account
|
| 158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
def process_login(ip, cookie, account, password, captcha, time_mode, custom_time, ow, tw, iw, dw):
|
| 160 |
valid_captcha = "FEIK"
|
| 161 |
def fail_response(msg, df):
|
|
|
|
| 240 |
gr.Markdown("### 資訊系統")
|
| 241 |
welcome_text = gr.Markdown(value="", elem_classes="text-right")
|
| 242 |
logout_btn = gr.Button("登出", size="sm")
|
| 243 |
+
with gr.Row():
|
| 244 |
+
btn_switch_student = gr.Button("🔄 快速切換為學生 (Student) 視角", size="sm", variant="secondary")
|
| 245 |
+
btn_switch_admin = gr.Button("🔄 快速切換為管理員 (Admin) 視角", size="sm", variant="secondary")
|
| 246 |
gr.Markdown("---")
|
| 247 |
|
| 248 |
with gr.Column(visible=False) as student_view:
|
|
|
|
| 249 |
with gr.Accordion("▼ 1. 教務系統", open=True):
|
| 250 |
with gr.Row(): btn_eval = gr.Button("▶ 期末網路教學評量", size="sm"); btn_pre_select = gr.Button("▶ 期末網路預選系統", size="sm"); btn_add_drop = gr.Button("▶ 開學後加退選系統", size="sm")
|
| 251 |
with gr.Row(): btn_istudy = gr.Button("▶ 北科i學園PLUS", size="sm"); btn_card = gr.Button("▶ 學生證掛失及補發系統", size="sm"); btn_course = gr.Button("▶ 課程系統", size="sm")
|
|
|
|
| 258 |
btn_hack_score = gr.Button("💀 嘗試偷改成績 (SQL Injection)", variant="stop", size="sm")
|
| 259 |
|
| 260 |
with gr.Column(visible=False) as admin_view:
|
|
|
|
| 261 |
with gr.Accordion("▼ 防護強度微調 (AI 敏感度)", open=True, elem_classes="weight-card"):
|
| 262 |
gr.Markdown("<span style='color:gray; font-size:0.9em;'>手動輸入 0~100 的數值。提高強度會增加誤報率,但能更有效攔截新型攻擊。</span>")
|
| 263 |
with gr.Row():
|
|
|
|
| 332 |
|
| 333 |
btn_fast_student.click(fn=lambda ip, c, tm, ct, ow, tw, iw, dw: fast_login("student", ip, c, tm, ct, ow, tw, iw, dw), inputs=fast_inputs, outputs=fast_outputs)
|
| 334 |
btn_fast_admin.click(fn=lambda ip, c, tm, ct, ow, tw, iw, dw: fast_login("admin", ip, c, tm, ct, ow, tw, iw, dw), inputs=fast_inputs, outputs=fast_outputs)
|
| 335 |
+
btn_switch_admin.click(fn=lambda ip, c, tm, ct, ow, tw, iw, dw: fast_login("admin", ip, c, tm, ct, ow, tw, iw, dw), inputs=fast_inputs, outputs=fast_outputs)
|
| 336 |
+
btn_switch_student.click(fn=lambda ip, c, tm, ct, ow, tw, iw, dw: fast_login("student", ip, c, tm, ct, ow, tw, iw, dw), inputs=fast_inputs, outputs=fast_outputs)
|
| 337 |
+
|
|
|
|
|
|
|
| 338 |
action_mapping = [
|
| 339 |
(btn_eval, "click_eval_system"), (btn_pre_select, "click_pre_select_system"),
|
| 340 |
(btn_add_drop, "click_add_drop_system"), (btn_istudy, "click_istudy"),
|