Tuchuanhuhuhu commited on
Commit
29b4859
1 Parent(s): c98021c

feat: 支持不中断服务器修改用户密码

Browse files
Files changed (2) hide show
  1. ChuanhuChatbot.py +1 -1
  2. modules/utils.py +13 -1
ChuanhuChatbot.py CHANGED
@@ -517,7 +517,7 @@ if __name__ == "__main__":
517
  server_name=server_name,
518
  server_port=server_port,
519
  share=share,
520
- auth=auth_list if authflag else None,
521
  favicon_path="./assets/favicon.ico",
522
  inbrowser=not dockerflag, # 禁止在docker下开启inbrowser
523
  )
 
517
  server_name=server_name,
518
  server_port=server_port,
519
  share=share,
520
+ auth=auth_from_conf if authflag else None,
521
  favicon_path="./assets/favicon.ico",
522
  inbrowser=not dockerflag, # 禁止在docker下开启inbrowser
523
  )
modules/utils.py CHANGED
@@ -2,7 +2,7 @@
2
  from __future__ import annotations
3
  from typing import TYPE_CHECKING, Any, Callable, Dict, List, Tuple, Type
4
  import logging
5
- import json
6
  import os
7
  import datetime
8
  from datetime import timezone
@@ -715,3 +715,15 @@ def beautify_err_msg(err_msg):
715
  if "Resource not found" in err_msg:
716
  return i18n("请查看 config_example.json,配置 Azure OpenAI")
717
  return err_msg
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  from __future__ import annotations
3
  from typing import TYPE_CHECKING, Any, Callable, Dict, List, Tuple, Type
4
  import logging
5
+ import commentjson as json
6
  import os
7
  import datetime
8
  from datetime import timezone
 
715
  if "Resource not found" in err_msg:
716
  return i18n("请查看 config_example.json,配置 Azure OpenAI")
717
  return err_msg
718
+
719
+ def auth_from_conf(username, password):
720
+ try:
721
+ with open("config.json", encoding="utf-8") as f:
722
+ conf = json.load(f)
723
+ usernames, passwords = [i[0] for i in conf["users"]], [i[1] for i in conf["users"]]
724
+ if username in usernames:
725
+ if passwords[usernames.index(username)] == password:
726
+ return True
727
+ return False
728
+ except:
729
+ return False