fix: arreglar conexión con google auth y proceso de arreglar conexión entre paso2 y paso3
This commit is contained in:
@@ -35,7 +35,7 @@ class DoCIT2MFRequest(BaseModel):
|
||||
def support_valid(cls, v, info):
|
||||
c, d = v
|
||||
if c >= d:
|
||||
raise ValueError("El soporte debe cumplir c < d.")
|
||||
raise ValueError("El soporte debe cumplir c <= d.")
|
||||
|
||||
core = info.data.get("core")
|
||||
if core:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# api/routers/docit2mf_build.py
|
||||
|
||||
import logging
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from fastapi import APIRouter, HTTPException, Request
|
||||
from slowapi import Limiter
|
||||
from slowapi.util import get_remote_address
|
||||
from api.models.docit2mf_models import DoCIT2MFMultiRequest
|
||||
@@ -14,11 +14,11 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
@router.post("/doc-it2mf/build")
|
||||
@limiter.limit("10/minute")
|
||||
async def build_doc_it2mf(request: DoCIT2MFMultiRequest):
|
||||
async def build_doc_it2mf(request: Request, body: DoCIT2MFMultiRequest):
|
||||
results = []
|
||||
|
||||
try:
|
||||
for level in request.levels:
|
||||
for level in body.levels:
|
||||
results.append(build_it2mf_from_level(level))
|
||||
except ValueError as e:
|
||||
logger.warning(f"Validation error in doc-it2mf/build: {str(e)}")
|
||||
@@ -27,4 +27,4 @@ async def build_doc_it2mf(request: DoCIT2MFMultiRequest):
|
||||
logger.error(f"Unexpected error in doc-it2mf/build: {str(e)}", exc_info=True)
|
||||
raise HTTPException(status_code=500, detail="Internal server error")
|
||||
|
||||
return {"levels": results}
|
||||
return {"levels": results}
|
||||
@@ -1,19 +1,18 @@
|
||||
# api/routers/google_auth.py
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Request
|
||||
from fastapi.responses import RedirectResponse
|
||||
from datetime import datetime, timedelta
|
||||
import httpx
|
||||
import os
|
||||
import jwt
|
||||
|
||||
from api.database.mongodb import users_collection
|
||||
from api.utils.security import create_access_token
|
||||
|
||||
router = APIRouter(prefix="/auth/google", tags=["auth"])
|
||||
|
||||
GOOGLE_CLIENT_ID = os.getenv("GOOGLE_CLIENT_ID")
|
||||
GOOGLE_CLIENT_SECRET = os.getenv("GOOGLE_CLIENT_SECRET")
|
||||
REDIRECT_URI = os.getenv("GOOGLE_REDIRECT_URI")
|
||||
SECRET_KEY = os.getenv("SECRET_KEY")
|
||||
|
||||
|
||||
# -----------------------------
|
||||
@@ -90,6 +89,20 @@ async def google_callback(request: Request):
|
||||
else:
|
||||
user_id = user["_id"]
|
||||
|
||||
token = create_access_token({"user_id": str(user_id)})
|
||||
token = jwt.encode(
|
||||
{
|
||||
"sub": str(user_id),
|
||||
"email": email,
|
||||
"name": name,
|
||||
"exp": datetime.utcnow() + timedelta(hours=24)
|
||||
},
|
||||
SECRET_KEY,
|
||||
algorithm="HS256"
|
||||
)
|
||||
|
||||
return RedirectResponse(f"http://localhost:5173/login?token={token}")
|
||||
await users_collection.update_one(
|
||||
{"_id": user_id},
|
||||
{"$set": {"token": token}}
|
||||
)
|
||||
|
||||
return RedirectResponse(f"http://localhost:5173/login?token={token}")
|
||||
Reference in New Issue
Block a user