Spaces:
Sleeping
Sleeping
Synced repo using 'sync_with_huggingface' Github Action
Browse files- main.py +3 -1
- requirements.txt +1 -0
- src/config/appConfig.py +1 -0
- src/controllers/auth/auth_controller.py +34 -1
- src/helpers/send_request.py +4 -2
main.py
CHANGED
@@ -2,15 +2,17 @@ from fastapi import FastAPI
|
|
2 |
from src.config.appConfig import ENV_VAR
|
3 |
from starlette.middleware.gzip import GZipMiddleware
|
4 |
from starlette.middleware.cors import CORSMiddleware
|
|
|
5 |
|
6 |
from src.main import main
|
7 |
|
8 |
# import os
|
9 |
-
origins = ["http://localhost:3000","https://chatbothub.vercel.app"]
|
10 |
|
11 |
# origins = os.getenv("ALLOWED_ORIGINS", "").split(",")
|
12 |
app = FastAPI(debug=ENV_VAR.DEBUG)
|
13 |
|
|
|
14 |
app.add_middleware(GZipMiddleware)
|
15 |
app.add_middleware(
|
16 |
CORSMiddleware,
|
|
|
2 |
from src.config.appConfig import ENV_VAR
|
3 |
from starlette.middleware.gzip import GZipMiddleware
|
4 |
from starlette.middleware.cors import CORSMiddleware
|
5 |
+
from starlette.middleware.sessions import SessionMiddleware
|
6 |
|
7 |
from src.main import main
|
8 |
|
9 |
# import os
|
10 |
+
origins = ["http://localhost:3000", "https://chatbothub.vercel.app"]
|
11 |
|
12 |
# origins = os.getenv("ALLOWED_ORIGINS", "").split(",")
|
13 |
app = FastAPI(debug=ENV_VAR.DEBUG)
|
14 |
|
15 |
+
app.add_middleware(SessionMiddleware, secret_key=ENV_VAR.SESSION_SECRET)
|
16 |
app.add_middleware(GZipMiddleware)
|
17 |
app.add_middleware(
|
18 |
CORSMiddleware,
|
requirements.txt
CHANGED
@@ -2,6 +2,7 @@ langchain==0.1.8
|
|
2 |
python-dotenv==1.0.0
|
3 |
huggingface_hub
|
4 |
typing
|
|
|
5 |
|
6 |
# pdf
|
7 |
PyPDF2==3.0.1
|
|
|
2 |
python-dotenv==1.0.0
|
3 |
huggingface_hub
|
4 |
typing
|
5 |
+
itsdangerous
|
6 |
|
7 |
# pdf
|
8 |
PyPDF2==3.0.1
|
src/config/appConfig.py
CHANGED
@@ -16,6 +16,7 @@ class ENV_VAR():
|
|
16 |
HUGGINGFACEHUB_API_TOKEN = os.environ.get("HUGGINGFACEHUB_API_TOKEN")
|
17 |
MONGO_DB_NAME_CACHE = os.environ.get("MONGO_DB_NAME_CACHE")
|
18 |
JWT_SECRET = os.environ.get("JWT_SECRET")
|
|
|
19 |
AUTH_API_END = os.environ.get("AUTH_API_END")
|
20 |
DEBUG = (
|
21 |
os.environ.get("DEBUG").lower() == "true" if os.environ.get("DEBUG") else False
|
|
|
16 |
HUGGINGFACEHUB_API_TOKEN = os.environ.get("HUGGINGFACEHUB_API_TOKEN")
|
17 |
MONGO_DB_NAME_CACHE = os.environ.get("MONGO_DB_NAME_CACHE")
|
18 |
JWT_SECRET = os.environ.get("JWT_SECRET")
|
19 |
+
SESSION_SECRET = os.environ.get("SESSION_SECRET")
|
20 |
AUTH_API_END = os.environ.get("AUTH_API_END")
|
21 |
DEBUG = (
|
22 |
os.environ.get("DEBUG").lower() == "true" if os.environ.get("DEBUG") else False
|
src/controllers/auth/auth_controller.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
-
from fastapi import APIRouter,
|
|
|
2 |
from src.config.appConfig import ENV_VAR
|
3 |
from src.helpers.response import ResponseHandler
|
4 |
from src.helpers.send_request import sendRequest
|
@@ -39,6 +40,16 @@ async def get_user_names():
|
|
39 |
return ResponseHandler.error(9999, e)
|
40 |
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
@router.post("/login/")
|
43 |
async def login_control(req: dict):
|
44 |
try:
|
@@ -61,3 +72,25 @@ async def change_pass_control(req: dict, authorization: str = None):
|
|
61 |
return ResponseHandler.success_mediator(response)
|
62 |
except Exception as e:
|
63 |
return ResponseHandler.error(9999, e)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import APIRouter, Request, UploadFile
|
2 |
+
from fastapi.responses import RedirectResponse
|
3 |
from src.config.appConfig import ENV_VAR
|
4 |
from src.helpers.response import ResponseHandler
|
5 |
from src.helpers.send_request import sendRequest
|
|
|
40 |
return ResponseHandler.error(9999, e)
|
41 |
|
42 |
|
43 |
+
@router.get("/login/google/")
|
44 |
+
async def google_login_control(req: Request, baseurl: str):
|
45 |
+
try:
|
46 |
+
# Construct the URL with the query parameters
|
47 |
+
auth_url = f"{AUTH_API_END}/api/v1/auth/google?baseurl={baseurl}"
|
48 |
+
return RedirectResponse(url=auth_url)
|
49 |
+
except Exception as e:
|
50 |
+
return ResponseHandler.error(9999, e)
|
51 |
+
|
52 |
+
|
53 |
@router.post("/login/")
|
54 |
async def login_control(req: dict):
|
55 |
try:
|
|
|
72 |
return ResponseHandler.success_mediator(response)
|
73 |
except Exception as e:
|
74 |
return ResponseHandler.error(9999, e)
|
75 |
+
|
76 |
+
|
77 |
+
@router.get("/get/session/")
|
78 |
+
async def get_session(req: Request):
|
79 |
+
try:
|
80 |
+
response = sendRequest(
|
81 |
+
f"{AUTH_API_END}/api/v1/auth/get/session/", "get", cookies=req.cookies
|
82 |
+
)
|
83 |
+
return ResponseHandler.success_mediator(response)
|
84 |
+
except Exception as e:
|
85 |
+
return ResponseHandler.error(9999, e)
|
86 |
+
|
87 |
+
|
88 |
+
@router.get("/logout/")
|
89 |
+
async def logout_control(req: Request):
|
90 |
+
try:
|
91 |
+
response = sendRequest(
|
92 |
+
f"{AUTH_API_END}/api/v1/auth/logout/", "get", cookies=req.cookies
|
93 |
+
)
|
94 |
+
return ResponseHandler.success_mediator(response)
|
95 |
+
except Exception as e:
|
96 |
+
return ResponseHandler.error(9999, e)
|
src/helpers/send_request.py
CHANGED
@@ -1,10 +1,12 @@
|
|
1 |
from requests import request
|
2 |
|
3 |
|
4 |
-
def sendRequest(url, method="get", data=None, files=None, headers=None):
|
5 |
try:
|
6 |
if files:
|
7 |
-
return request(
|
|
|
|
|
8 |
return request(method, url, json=data, headers=headers)
|
9 |
except Exception as e:
|
10 |
# Handle exceptions and return None
|
|
|
1 |
from requests import request
|
2 |
|
3 |
|
4 |
+
def sendRequest(url, method="get", data=None, files=None, headers=None, cookies=None):
|
5 |
try:
|
6 |
if files:
|
7 |
+
return request(
|
8 |
+
method, url, data=data, files=files, headers=headers, cookies=cookies
|
9 |
+
)
|
10 |
return request(method, url, json=data, headers=headers)
|
11 |
except Exception as e:
|
12 |
# Handle exceptions and return None
|