GuXiaopeng commited on
Commit
d2cde3b
·
verified ·
1 Parent(s): bd7a550

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -1
app.py CHANGED
@@ -29,6 +29,7 @@ from config import APP_CONFIG, AMJ_PROMPTS, ASQ_PROMPTS, GENERIC_PROMPTS
29
  from utils.file_parser import extract_text_from_files, extract_data_from_files
30
  from utils.docx_builder import text_to_docx
31
  from core.pipeline_agent import SSciPipelineAgent
 
32
 
33
  os.environ["STREAMLIT_SERVER_ENABLE_CORS"] = "false"
34
  os.environ["STREAMLIT_SERVER_ENABLE_XSRF_PROTECTION"] = "false"
@@ -139,7 +140,66 @@ def check_password():
139
  def get_global_lock():
140
  return threading.Lock()
141
 
142
- check_password()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  global_lock = get_global_lock()
144
 
145
  # =====================================================================
 
29
  from utils.file_parser import extract_text_from_files, extract_data_from_files
30
  from utils.docx_builder import text_to_docx
31
  from core.pipeline_agent import SSciPipelineAgent
32
+ from managed_auth import require_alipay_login
33
 
34
  os.environ["STREAMLIT_SERVER_ENABLE_CORS"] = "false"
35
  os.environ["STREAMLIT_SERVER_ENABLE_XSRF_PROTECTION"] = "false"
 
140
  def get_global_lock():
141
  return threading.Lock()
142
 
143
+ SMARTPAPER_MODE = (
144
+ _read_runtime_secret("SMARTPAPER_MODE") or "legacy"
145
+ ).lower()
146
+
147
+ if SMARTPAPER_MODE == "legacy":
148
+ # 原系统:所有用户继续使用原密码。
149
+ check_password()
150
+
151
+ elif SMARTPAPER_MODE == "pilot":
152
+ # 试运行:普通用户使用原密码,管理员测试支付宝登录。
153
+ access_method = st.radio(
154
+ "访问方式",
155
+ ["原密码登录", "支付宝试运行"],
156
+ horizontal=True,
157
+ key="smartpaper_access_method",
158
+ )
159
+
160
+ if access_method == "原密码登录":
161
+ check_password()
162
+
163
+ else:
164
+ expected_pilot_key = _read_runtime_secret(
165
+ "SMARTPAPER_PILOT_KEY"
166
+ )
167
+
168
+ if not expected_pilot_key:
169
+ st.error("尚未配置 SMARTPAPER_PILOT_KEY。")
170
+ st.stop()
171
+
172
+ if not st.session_state.get("pilot_key_verified", False):
173
+ st.markdown("### 管理员试运行验证")
174
+
175
+ pilot_key = st.text_input(
176
+ "请输入试运行密钥",
177
+ type="password",
178
+ key="pilot_key_input",
179
+ )
180
+
181
+ if st.button("进入支付宝试运行"):
182
+ if pilot_key == expected_pilot_key:
183
+ st.session_state["pilot_key_verified"] = True
184
+ st.rerun()
185
+ else:
186
+ st.error("试运行密钥不正确。")
187
+
188
+ st.stop()
189
+
190
+ require_alipay_login()
191
+
192
+ elif SMARTPAPER_MODE == "managed":
193
+ # 正式模式:所有用户必须支付宝登录。
194
+ require_alipay_login()
195
+
196
+ else:
197
+ # 非法或误填模式自动退回原系统。
198
+ st.warning(
199
+ f"SMARTPAPER_MODE={SMARTPAPER_MODE!r} 无效,已自动退回 legacy。"
200
+ )
201
+ check_password()
202
+
203
  global_lock = get_global_lock()
204
 
205
  # =====================================================================