kenken999 commited on
Commit
57b26e3
1 Parent(s): 26ed253
Files changed (2) hide show
  1. chat_history.db +0 -0
  2. mysite/asgi.py +34 -0
chat_history.db CHANGED
Binary files a/chat_history.db and b/chat_history.db differ
 
mysite/asgi.py CHANGED
@@ -15,7 +15,29 @@ from interpreter import interpreter
15
  import mysite.interpreter.interpreter_config # インポートするだけで設定が適用されます
16
  # ロガーの設定
17
  from mysite.logger import logger
 
 
 
 
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
  os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
21
  application = get_asgi_application()
@@ -34,6 +56,18 @@ app.add_middleware(
34
  allow_headers=["*"],
35
  )
36
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  # Gradioインターフェースの設定
38
  gradio_interfaces = setup_gradio_interfaces()
39
 
 
15
  import mysite.interpreter.interpreter_config # インポートするだけで設定が適用されます
16
  # ロガーの設定
17
  from mysite.logger import logger
18
+ from fastapi import Depends, HTTPException, status
19
+ from fastapi.security import HTTPBasic, HTTPBasicCredentials
20
+ from starlette.middleware.base import BaseHTTPMiddleware
21
+ import secrets
22
 
23
+ security = HTTPBasic()
24
+
25
+ # ベーシック認証のユーザー名とパスワード
26
+ users = {
27
+ "username1": "password1",
28
+ "username2": "password2"
29
+ }
30
+
31
+ def authenticate(credentials: HTTPBasicCredentials = Depends(security)):
32
+ correct_username = secrets.compare_digest(credentials.username, "username1")
33
+ correct_password = secrets.compare_digest(credentials.password, users[credentials.username]) if correct_username else False
34
+ if not (correct_username and correct_password):
35
+ raise HTTPException(
36
+ status_code=status.HTTP_401_UNAUTHORIZED,
37
+ detail="Invalid credentials",
38
+ headers={"WWW-Authenticate": "Basic"},
39
+ )
40
+ return credentials.username
41
 
42
  os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
43
  application = get_asgi_application()
 
56
  allow_headers=["*"],
57
  )
58
 
59
+ # 認証用ミドルウェア
60
+ """
61
+ @app.middleware("http")
62
+ async def auth_middleware(request, call_next):
63
+ if request.url.path.startswith("/"):
64
+ credentials = HTTPBasicCredentials(username=request.headers.get("authorization").split()[1].split(':')[0],
65
+ password=request.headers.get("authorization").split()[1].split(':')[1])
66
+ authenticate(credentials)
67
+ response = await call_next(request)
68
+ return response
69
+ """
70
+
71
  # Gradioインターフェースの設定
72
  gradio_interfaces = setup_gradio_interfaces()
73