mirror of
https://github.com/maxdorninger/MediaManager.git
synced 2026-04-26 15:55:19 +02:00
add ability to create user, add password auth, add logging and work on dev containers
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from typing import Annotated
|
||||
|
||||
import bcrypt
|
||||
import jwt
|
||||
from fastapi import Depends, FastAPI, HTTPException, status, APIRouter
|
||||
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
|
||||
@@ -37,7 +38,6 @@ class Token(BaseModel):
|
||||
class TokenData(BaseModel):
|
||||
username: str | None = None
|
||||
|
||||
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
||||
|
||||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
|
||||
|
||||
@@ -45,11 +45,17 @@ app = APIRouter()
|
||||
|
||||
|
||||
def verify_password(plain_password, hashed_password):
|
||||
return pwd_context.verify(plain_password, hashed_password)
|
||||
return bcrypt.checkpw(
|
||||
bytes(plain_password, encoding="utf-8"),
|
||||
bytes(hashed_password, encoding="utf-8"),
|
||||
)
|
||||
|
||||
|
||||
def get_password_hash(password):
|
||||
return pwd_context.hash(password)
|
||||
return bcrypt.hashpw(
|
||||
bytes(password, encoding="utf-8"),
|
||||
bcrypt.gensalt(),
|
||||
)
|
||||
|
||||
|
||||
def authenticate_user(email: str, password: str) -> UserInternal:
|
||||
@@ -105,6 +111,6 @@ async def login_for_access_token(
|
||||
)
|
||||
access_token_expires = timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES)
|
||||
access_token = create_access_token(
|
||||
data={"sub": user.username}, expires_delta=access_token_expires
|
||||
data={"sub": user.email}, expires_delta=access_token_expires
|
||||
)
|
||||
return Token(access_token=access_token, token_type="bearer")
|
||||
Reference in New Issue
Block a user