first commit

This commit is contained in:
2026-03-07 21:31:38 +03:00
commit a879ba7b50
68 changed files with 2487 additions and 0 deletions

1
app/email/__init__.py Normal file
View File

@@ -0,0 +1 @@

16
app/email/models.py Normal file
View File

@@ -0,0 +1,16 @@
from datetime import datetime
from sqlalchemy import DateTime, String, Text, func
from sqlalchemy.orm import Mapped, mapped_column
from app.database.base import Base
class EmailLog(Base):
__tablename__ = "email_logs"
id: Mapped[int] = mapped_column(primary_key=True, index=True)
recipient: Mapped[str] = mapped_column(String(255), index=True, nullable=False)
subject: Mapped[str] = mapped_column(String(255), nullable=False)
body: Mapped[str] = mapped_column(Text, nullable=False)
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now(), nullable=False)

7
app/email/repository.py Normal file
View File

@@ -0,0 +1,7 @@
from sqlalchemy.ext.asyncio import AsyncSession
from app.email.models import EmailLog
async def create_email_log(db: AsyncSession, *, recipient: str, subject: str, body: str) -> None:
db.add(EmailLog(recipient=recipient, subject=subject, body=body))

3
app/email/router.py Normal file
View File

@@ -0,0 +1,3 @@
from fastapi import APIRouter
router = APIRouter(prefix="/email", tags=["email"])

7
app/email/schemas.py Normal file
View File

@@ -0,0 +1,7 @@
from pydantic import BaseModel, EmailStr
class EmailPayload(BaseModel):
recipient: EmailStr
subject: str
body: str

23
app/email/service.py Normal file
View File

@@ -0,0 +1,23 @@
import logging
from app.config.settings import settings
logger = logging.getLogger(__name__)
class EmailService:
async def send_verification_email(self, email: str, token: str) -> None:
verify_link = f"{settings.frontend_base_url}/verify-email?token={token}"
subject = "Verify your BenyaMessenger account"
body = f"Open this link to verify your account: {verify_link}"
logger.info("EMAIL to=%s subject=%s body=%s", email, subject, body)
async def send_password_reset_email(self, email: str, token: str) -> None:
reset_link = f"{settings.frontend_base_url}/reset-password?token={token}"
subject = "Reset your BenyaMessenger password"
body = f"Open this link to reset your password: {reset_link}"
logger.info("EMAIL to=%s subject=%s body=%s", email, subject, body)
def get_email_service() -> EmailService:
return EmailService()