Update main.py
Browse files
main.py
CHANGED
@@ -371,9 +371,28 @@ async def register_post(
|
|
371 |
|
372 |
|
373 |
@app.get("/registration_successful", response_class=HTMLResponse)
|
374 |
-
async def registration_successful(request: Request):
|
375 |
-
#
|
376 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
377 |
|
378 |
|
379 |
@app.get("/verify", response_class=HTMLResponse)
|
|
|
371 |
|
372 |
|
373 |
@app.get("/registration_successful", response_class=HTMLResponse)
|
374 |
+
async def registration_successful(request: Request, db: Session = Depends(get_db)):
|
375 |
+
# Assuming the OAuth process has been completed and user info is stored in the session or a similar mechanism
|
376 |
+
user_info = request.session.get("user_info") # Replace with your method of retrieving user info
|
377 |
+
|
378 |
+
if not user_info:
|
379 |
+
raise HTTPException(status_code=401, detail="User not authenticated")
|
380 |
+
|
381 |
+
email = user_info["email"]
|
382 |
+
db_user = db.query(User).filter(User.email == email).first()
|
383 |
+
if not db_user:
|
384 |
+
raise HTTPException(status_code=404, detail="User not found")
|
385 |
+
|
386 |
+
# Create an access token for the user
|
387 |
+
access_token = auth_views.create_access_token(
|
388 |
+
data={"sub": db_user.email},
|
389 |
+
expires_delta=timedelta(minutes=auth_views.ACCESS_TOKEN_EXPIRE_MINUTES)
|
390 |
+
)
|
391 |
+
|
392 |
+
# Redirect the user to the protected route
|
393 |
+
response = RedirectResponse(url="/protected")
|
394 |
+
response.set_cookie(key="access_token", value=f"Bearer {access_token}", httponly=True)
|
395 |
+
return response
|
396 |
|
397 |
|
398 |
@app.get("/verify", response_class=HTMLResponse)
|