Ajout admin
Build & Deploy / build (push) Successful in 41s

This commit is contained in:
Mouigni
2026-08-13 23:46:41 +02:00
parent c4aeedd032
commit ad84286259
3 changed files with 155 additions and 79 deletions
+6 -3
View File
@@ -4,7 +4,7 @@ from jose import JWTError, jwt
from passlib.context import CryptContext
from pydantic import BaseModel, EmailStr
SECRET_KEY = "your-secret-key-change-in-production"
SECRET_KEY = "your-secret-key-change-in-production"
ALGORITHM = "HS256"
ACCESS_TOKEN_EXPIRE_MINUTES = 30
@@ -30,6 +30,10 @@ class UserResponse(BaseModel):
id: int
email: str
full_name: Optional[str] = None
role: str = "user" # ← nouveau
class RoleUpdate(BaseModel):
role: str
def verify_password(plain_password: str, hashed_password: str) -> bool:
return pwd_context.verify(plain_password, hashed_password)
@@ -44,8 +48,7 @@ def create_access_token(data: dict, expires_delta: Optional[timedelta] = None):
else:
expire = datetime.now(timezone.utc) + timedelta(minutes=15)
to_encode.update({"exp": expire})
encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
return encoded_jwt
return jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
def decode_token(token: str) -> Optional[str]:
try: