diff --git a/config/app.env.example b/config/app.env.example index 946cc15..5f18dd1 100644 --- a/config/app.env.example +++ b/config/app.env.example @@ -1 +1,7 @@ -SECRET_KEY="SECRET_KEY" \ No newline at end of file +SECRET_KEY="SECRET_KEY" +SMTP_HOST="smtp.gmail.com" +SMTP_PORT=587 +SMTP_SSL_TLS=False +SMTP_USER="SMTP_USER" +SMTP_PASSWORD="SMTP_PASSWORD" +EMAIL_RECIPIENTS=["EMAIL_RECIPIENT", "EMAIL_RECIPIENT"] \ No newline at end of file diff --git a/src/app/core/config.py b/src/app/core/config.py index ba51c83..edb0b60 100644 --- a/src/app/core/config.py +++ b/src/app/core/config.py @@ -1,7 +1,12 @@ -from pydantic import PostgresDsn -from pydantic_settings import BaseSettings +from typing import Optional from pathlib import Path +from pydantic_settings import BaseSettings +from pydantic import ( + EmailStr, + PostgresDsn +) + class Settings(BaseSettings): PROJECT_NAME: str = 'FastAPI Portfolio & Blog' @@ -36,5 +41,14 @@ class Settings(BaseSettings): path=self.POSTGRES_DB ) + SMTP_SSL_TLS: bool = True + SMTP_PORT: int = 587 + SMTP_HOST: str = "smtp.gmail.com" + SMTP_USER: EmailStr + SMTP_PASSWORD: str + + EMAILS_FROM_NAME: str = PROJECT_NAME + EMAIL_RECIPIENTS: list[EmailStr] = [] + settings = Settings() \ No newline at end of file diff --git a/src/app/main.py b/src/app/main.py index cdb03d3..03c25a8 100644 --- a/src/app/main.py +++ b/src/app/main.py @@ -40,30 +40,6 @@ app = FastAPI( app.include_router(main_router) -# templates = Jinja2Templates(directory=main_path / 'templates') - - - -# @app.get("/", response_class=HTMLResponse) -# async def read_item(request: Request): -# return templates.TemplateResponse("test.html", {"request": request}) - -# from pydantic import BaseModel - - -# class User(BaseModel): -# username: str -# password: str - -# @app.post("/", response_class=HTMLResponse) -# async def read_item(request: Request, user: User): -# print(user) -# return templates.TemplateResponse("index.html", {"request": request}) - -# @app.get("/t", response_class=HTMLResponse) -# async def read_item(request: Request): -# return templates.TemplateResponse("index.html", {"request": request}) - @app.exception_handler(ValidationError) async def validation_exception_handler(request, exc): diff --git a/src/app/schemas/main.py b/src/app/schemas/main.py new file mode 100644 index 0000000..97534d4 --- /dev/null +++ b/src/app/schemas/main.py @@ -0,0 +1,14 @@ +from dataclasses import dataclass +from typing import Optional + +from fastapi import Form + +from pydantic import EmailStr + + +@dataclass +class SendEmail: + name: str = Form(..., max_length=50) + email: EmailStr = Form(...) + phone: Optional[str] = Form(None, max_length=20) + message: str = Form(..., max_length=1000) \ No newline at end of file diff --git a/src/app/templates/index.html b/src/app/templates/index.html index 62dc2f0..0fbcf6f 100644 --- a/src/app/templates/index.html +++ b/src/app/templates/index.html @@ -56,18 +56,18 @@
Want to get in touch? Fill out the form below to send me a message and I will get back to you as soon as possible!
-