Initial commit: Ebook Translation System with Docker setup
This commit is contained in:
30
ebook_backend&admin_panel/admin-backend/utils/auth.py
Normal file
30
ebook_backend&admin_panel/admin-backend/utils/auth.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import declarative_base
|
||||
from passlib.context import CryptContext
|
||||
|
||||
# Load environment variables
|
||||
load_dotenv()
|
||||
|
||||
DATABASE_URL = os.getenv("DATABASE_URL", "postgresql://postgres:postgres@localhost:5432/postgres")
|
||||
|
||||
engine = create_engine(DATABASE_URL)
|
||||
SessionLocal = sessionmaker(bind=engine)
|
||||
Base = declarative_base()
|
||||
|
||||
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
||||
|
||||
def get_db():
|
||||
db = SessionLocal()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
def hash_password(pw: str) -> str:
|
||||
return pwd_context.hash(pw)
|
||||
|
||||
def verify_password(pw: str, hashed: str) -> bool:
|
||||
return pwd_context.verify(pw, hashed)
|
||||
Reference in New Issue
Block a user