Spaces:
Sleeping
Sleeping
very scripted
Browse files- app.py +28 -8
- streaksManagement.py +0 -2
- tokenManagement.py +33 -3
- utils.py +2 -3
app.py
CHANGED
|
@@ -69,7 +69,7 @@ def extract_course_info(text: str) -> CourseRecommendation:
|
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
-
@app.get("/
|
| 73 |
def get_course(query):
|
| 74 |
# Example search query
|
| 75 |
results = google_search(query, API_KEY, CX)
|
|
@@ -120,7 +120,7 @@ def get_course_func(query):
|
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
-
@app.post("/upload",tags=["AI"])
|
| 124 |
async def upload_file(file: UploadFile = File(...),authorization: str = Header(...)):
|
| 125 |
# Extract the token from the Authorization header (Bearer token)
|
| 126 |
token = authorization.split("Bearer ")[-1]
|
|
@@ -162,7 +162,7 @@ async def upload_file(file: UploadFile = File(...),authorization: str = Header(.
|
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
-
@app.post("/ask",tags=["AI"])
|
| 166 |
def ask_ai_about_resume(req:AiAnalysis,authorization: str = Header(...)):
|
| 167 |
# Retrieve context from your vector database
|
| 168 |
token = authorization.split("Bearer ")[-1]
|
|
@@ -196,8 +196,8 @@ def ask_ai_about_resume(req:AiAnalysis,authorization: str = Header(...)):
|
|
| 196 |
|
| 197 |
return {"Ai_Response":response.text}
|
| 198 |
|
| 199 |
-
@app.post("/recommend
|
| 200 |
-
def
|
| 201 |
"""
|
| 202 |
User Profile Information for Career Development
|
| 203 |
|
|
@@ -281,7 +281,7 @@ Parameters:
|
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
-
@app.post("/login",tags=["Authentication"])
|
| 285 |
def login(user:UserBody):
|
| 286 |
user ={"email":user.email,"password":user.password,"firstName":user.firstName,"lastName":user.lastName}
|
| 287 |
user_id= login_user(db_uri=MONGO_URI,db_name="crayonics",collection_name="Users",document=user)
|
|
@@ -296,7 +296,7 @@ def login(user:UserBody):
|
|
| 296 |
return JSONResponse(status_code=401,content="Invalid login details")
|
| 297 |
|
| 298 |
|
| 299 |
-
@app.post("/signup",tags=["Authentication"])
|
| 300 |
def signUp(user:UserBody):
|
| 301 |
user ={"email":user.email,"password":user.password}
|
| 302 |
user_id= create_user(db_uri=MONGO_URI,db_name="crayonics",collection_name="users",document=user)
|
|
@@ -310,7 +310,27 @@ def signUp(user:UserBody):
|
|
| 310 |
return JSONResponse(status_code=401,content="Invalid Sign Up details")
|
| 311 |
|
| 312 |
|
| 313 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 314 |
def refresh_access_token(refresh_token:Token, authorization: str = Header(...)):
|
| 315 |
|
| 316 |
token = authorization.split("Bearer ")[-1]
|
|
|
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
+
@app.get("/courses",tags=["Scrape"])
|
| 73 |
def get_course(query):
|
| 74 |
# Example search query
|
| 75 |
results = google_search(query, API_KEY, CX)
|
|
|
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
+
@app.post("/Ai/upload",tags=["AI"])
|
| 124 |
async def upload_file(file: UploadFile = File(...),authorization: str = Header(...)):
|
| 125 |
# Extract the token from the Authorization header (Bearer token)
|
| 126 |
token = authorization.split("Bearer ")[-1]
|
|
|
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
+
@app.post("/Ai/ask",tags=["AI"])
|
| 166 |
def ask_ai_about_resume(req:AiAnalysis,authorization: str = Header(...)):
|
| 167 |
# Retrieve context from your vector database
|
| 168 |
token = authorization.split("Bearer ")[-1]
|
|
|
|
| 196 |
|
| 197 |
return {"Ai_Response":response.text}
|
| 198 |
|
| 199 |
+
@app.post("/Ai/recommend",tags=["AI"])
|
| 200 |
+
def ask_ai_to_recommnd_courses(request:UserCourse,authorization:str=Header(...)):
|
| 201 |
"""
|
| 202 |
User Profile Information for Career Development
|
| 203 |
|
|
|
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
+
@app.post("/auth/login",tags=["Authentication"])
|
| 285 |
def login(user:UserBody):
|
| 286 |
user ={"email":user.email,"password":user.password,"firstName":user.firstName,"lastName":user.lastName}
|
| 287 |
user_id= login_user(db_uri=MONGO_URI,db_name="crayonics",collection_name="Users",document=user)
|
|
|
|
| 296 |
return JSONResponse(status_code=401,content="Invalid login details")
|
| 297 |
|
| 298 |
|
| 299 |
+
@app.post("/auth/signup",tags=["Authentication"])
|
| 300 |
def signUp(user:UserBody):
|
| 301 |
user ={"email":user.email,"password":user.password}
|
| 302 |
user_id= create_user(db_uri=MONGO_URI,db_name="crayonics",collection_name="users",document=user)
|
|
|
|
| 310 |
return JSONResponse(status_code=401,content="Invalid Sign Up details")
|
| 311 |
|
| 312 |
|
| 313 |
+
|
| 314 |
+
|
| 315 |
+
@app.post("/auth/logout",tags=["Authentication"])
|
| 316 |
+
def signUp(refresh:Token,authorization: str = Header(...)):
|
| 317 |
+
|
| 318 |
+
token = authorization.split("Bearer ")[-1]
|
| 319 |
+
|
| 320 |
+
decoded_user_id,decoded_access_token = decode_jwt(token)
|
| 321 |
+
is_valid = verify_access_token(db_uri=MONGO_URI, user_id=decoded_user_id, access_token=decoded_access_token)
|
| 322 |
+
if is_valid != True: # Example check
|
| 323 |
+
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid token")
|
| 324 |
+
|
| 325 |
+
result = logout(db_uri=MONGO_URI,refresh_token= refresh.refreshToken)
|
| 326 |
+
if result ==True:
|
| 327 |
+
return {"content": f"successful"}
|
| 328 |
+
else:
|
| 329 |
+
return JSONResponse(status_code=status.HTTP_410_GONE,content={"content": f"unsuccessful"})
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
|
| 333 |
+
@app.post("/auth/refresh",tags=["Authentication"])
|
| 334 |
def refresh_access_token(refresh_token:Token, authorization: str = Header(...)):
|
| 335 |
|
| 336 |
token = authorization.split("Bearer ")[-1]
|
streaksManagement.py
CHANGED
|
@@ -68,5 +68,3 @@ def streaks_manager(db_uri: str, document: dict) -> str:
|
|
| 68 |
# Close the connection
|
| 69 |
|
| 70 |
|
| 71 |
-
|
| 72 |
-
# streaks_manager(db_uri="mongodb+srv://groupcresearchseminar:[email protected]/?retryWrites=true&w=majority&appName=Cluster0",document={"user_id":"67c9600773ef7350189a2d90"})
|
|
|
|
| 68 |
# Close the connection
|
| 69 |
|
| 70 |
|
|
|
|
|
|
tokenManagement.py
CHANGED
|
@@ -44,9 +44,7 @@ def create_accessToken(db_uri: str, user_id: str, refresh_token: str) -> str:
|
|
| 44 |
collection.find_one_and_delete({"refresh_token":refresh_token})
|
| 45 |
# Insert the document
|
| 46 |
result = collection.insert_one({"user_id":user_id,"refresh_token":refresh_token,"current_time":current_time,"expire_at":expire_at})
|
| 47 |
-
|
| 48 |
-
streaks_doc['user_id'] = user_id
|
| 49 |
-
streaks_manager(db_uri=db_uri,document=streaks_doc)
|
| 50 |
client.close()
|
| 51 |
return str(result.inserted_id)
|
| 52 |
|
|
@@ -150,3 +148,35 @@ def verify_access_token(db_uri: str, user_id: str, access_token: str) -> bool:
|
|
| 150 |
|
| 151 |
|
| 152 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
collection.find_one_and_delete({"refresh_token":refresh_token})
|
| 45 |
# Insert the document
|
| 46 |
result = collection.insert_one({"user_id":user_id,"refresh_token":refresh_token,"current_time":current_time,"expire_at":expire_at})
|
| 47 |
+
|
|
|
|
|
|
|
| 48 |
client.close()
|
| 49 |
return str(result.inserted_id)
|
| 50 |
|
|
|
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
def logout(db_uri: str, refresh_token: str) -> str:
|
| 154 |
+
from pymongo import MongoClient
|
| 155 |
+
current_time = datetime.datetime.now()
|
| 156 |
+
expire_at = current_time + datetime.timedelta(days=30)
|
| 157 |
+
|
| 158 |
+
"""
|
| 159 |
+
Inserts a new document into the specified MongoDB collection.
|
| 160 |
+
|
| 161 |
+
Parameters:
|
| 162 |
+
db_uri (str): MongoDB connection URI.
|
| 163 |
+
user_id (str): id of user .
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
Returns:
|
| 167 |
+
str: The ID of the inserted document.
|
| 168 |
+
"""
|
| 169 |
+
|
| 170 |
+
# Connect to MongoDB
|
| 171 |
+
client = MongoClient(db_uri)
|
| 172 |
+
db = client["crayonics"]
|
| 173 |
+
collection = db["RefreshToken"]
|
| 174 |
+
# Insert the document
|
| 175 |
+
result = collection.find_one_and_delete(filter={"_id":ObjectId(refresh_token)})
|
| 176 |
+
|
| 177 |
+
return True
|
| 178 |
+
|
| 179 |
+
# Close the connection
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
|
utils.py
CHANGED
|
@@ -137,9 +137,9 @@ def create_user(db_uri: str, db_name: str, collection_name: str, document: dict)
|
|
| 137 |
document['password']= password
|
| 138 |
if s==None:
|
| 139 |
result = collection.insert_one(document)
|
| 140 |
-
|
| 141 |
streaks_doc={}
|
| 142 |
-
streaks_doc['user_id'] = result.inserted_id
|
| 143 |
streaks_manager(db_uri=db_uri,document=streaks_doc)
|
| 144 |
return str(result.inserted_id)
|
| 145 |
else:
|
|
@@ -211,7 +211,6 @@ def login_user(db_uri: str, db_name: str, collection_name: str, document: dict)
|
|
| 211 |
if check_password(password=document['password'],hashed_password=s['password']):
|
| 212 |
streaks_doc['user_id'] = s.get("_id")
|
| 213 |
streaks_manager(db_uri=db_uri,document=streaks_doc)
|
| 214 |
-
client.close()
|
| 215 |
return str(s['_id'])
|
| 216 |
else:
|
| 217 |
return "Wrong Password"
|
|
|
|
| 137 |
document['password']= password
|
| 138 |
if s==None:
|
| 139 |
result = collection.insert_one(document)
|
| 140 |
+
|
| 141 |
streaks_doc={}
|
| 142 |
+
streaks_doc['user_id'] = str(result.inserted_id)
|
| 143 |
streaks_manager(db_uri=db_uri,document=streaks_doc)
|
| 144 |
return str(result.inserted_id)
|
| 145 |
else:
|
|
|
|
| 211 |
if check_password(password=document['password'],hashed_password=s['password']):
|
| 212 |
streaks_doc['user_id'] = s.get("_id")
|
| 213 |
streaks_manager(db_uri=db_uri,document=streaks_doc)
|
|
|
|
| 214 |
return str(s['_id'])
|
| 215 |
else:
|
| 216 |
return "Wrong Password"
|