Gregniuki commited on
Commit
8e04748
1 Parent(s): dc925e9

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +22 -3
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
- # Render the successful registration page
376
- return templates.TemplateResponse("registration_successful.html", {"request": request})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)