Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /farhan0167_otto-m8 /lib /otto_backend /routers /dependency.py
| from datetime import datetime | |
| from sqlalchemy.orm import Session | |
| from fastapi import Depends, HTTPException, status | |
| from fastapi.security import OAuth2PasswordBearer | |
| from redis import Redis | |
| from db.db_engine import get_db | |
| from db.models.users import Users | |
| from core.connections import redis_client | |
| # OAuth2 scheme for token-based authentication | |
| oauth2_scheme = OAuth2PasswordBearer(tokenUrl="login") | |
| def get_current_user(token: str = Depends(oauth2_scheme), db: Session = Depends(get_db)) -> Users: | |
| """Retrieve the current user based on the token.""" | |
| data = redis_client.hgetall(f"tokens:{token}") | |
| if not data: | |
| raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid or expired token") | |
| user = db.query(Users).filter_by(email=data['email']).first() | |
| if not user: | |
| raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="User not found") | |
| return user | |
Xet Storage Details
- Size:
- 935 Bytes
- Xet hash:
- 765bda9b42a07b85f844ef07496a0ce6c12dbabb7ba7f7a5f6f2b50cc1ee8df6
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.