first implementation

This commit is contained in:
counterweight 2025-12-20 22:18:14 +01:00
parent 1eb4641ed9
commit a56a4c076a
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
14 changed files with 898 additions and 729 deletions

View file

@ -4,12 +4,12 @@ from datetime import datetime, timedelta, timezone
import bcrypt
from fastapi import Depends, HTTPException, Request, status
from jose import JWTError, jwt
from pydantic import BaseModel, EmailStr
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from database import get_db
from models import User, Permission
from schemas import UserResponse
SECRET_KEY = os.environ["SECRET_KEY"] # Required - see .env.example
ALGORITHM = "HS256"
@ -17,28 +17,6 @@ ACCESS_TOKEN_EXPIRE_MINUTES = 60 * 24 * 7 # 7 days
COOKIE_NAME = "auth_token"
class UserCredentials(BaseModel):
email: EmailStr
password: str
UserCreate = UserCredentials
UserLogin = UserCredentials
class UserResponse(BaseModel):
id: int
email: str
roles: list[str]
permissions: list[str]
class TokenResponse(BaseModel):
access_token: str
token_type: str
user: UserResponse
def verify_password(plain_password: str, hashed_password: str) -> bool:
return bcrypt.checkpw(
plain_password.encode("utf-8"),