initial commit
This commit is contained in:
20
app/core/config.py
Normal file
20
app/core/config.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
app_name: str = "TK Wiki Newsletter Admin"
|
||||
environment: str = "production"
|
||||
secret_key: str = "change-me-in-production"
|
||||
algorithm: str = "HS256"
|
||||
access_token_expire_minutes: int = 120
|
||||
database_url: str = "sqlite:///./data/newsletter.db"
|
||||
wiki_api_url: str = "https://www.thomas-krenn.com/de/wiki/api.php"
|
||||
allowed_hosts: str = "*"
|
||||
cookie_secure: bool = True
|
||||
admin_bootstrap_email: str = "admin@internal.local"
|
||||
admin_bootstrap_password: str = "ChangeMe123!"
|
||||
|
||||
model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8")
|
||||
|
||||
|
||||
settings = Settings()
|
||||
24
app/core/security.py
Normal file
24
app/core/security.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from typing import Any
|
||||
|
||||
from jose import jwt
|
||||
from passlib.context import CryptContext
|
||||
|
||||
from app.core.config import settings
|
||||
|
||||
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
||||
|
||||
|
||||
def hash_password(password: str) -> str:
|
||||
return pwd_context.hash(password)
|
||||
|
||||
|
||||
def verify_password(plain_password: str, hashed_password: str) -> bool:
|
||||
return pwd_context.verify(plain_password, hashed_password)
|
||||
|
||||
|
||||
def create_access_token(subject: Any) -> str:
|
||||
expires_delta = timedelta(minutes=settings.access_token_expire_minutes)
|
||||
expire = datetime.now(timezone.utc) + expires_delta
|
||||
to_encode = {"exp": expire, "sub": str(subject)}
|
||||
return jwt.encode(to_encode, settings.secret_key, algorithm=settings.algorithm)
|
||||
Reference in New Issue
Block a user