diff --git a/app/api/deps.py b/app/api/deps.py index 90f832e..f8998c8 100644 --- a/app/api/deps.py +++ b/app/api/deps.py @@ -6,8 +6,10 @@ from sqlmodel import Session from app.core.db import engine + def get_db() -> Generator[Session, None, None]: with Session(engine) as session: yield session + SessionDep = Annotated[Session, Depends(get_db)] diff --git a/app/api/routes/registration.py b/app/api/routes/registration.py index b8320eb..e8bb860 100644 --- a/app/api/routes/registration.py +++ b/app/api/routes/registration.py @@ -5,27 +5,28 @@ from app.models import RegistrationCreate from app import crud from app.api.deps import SessionDep +from app.core.utils import is_registration_open + +from fastapi.responses import RedirectResponse + router = APIRouter(prefix="/registration") @router.post( - "/register", + "/register_form", ) -def register(*, session: SessionDep, registration_create: Annotated[RegistrationCreate, Form()]): - print(registration_create) +def register( + *, session: SessionDep, registration_create: Annotated[RegistrationCreate, Form()] +): """ Register """ - registration = crud.create_registration(session=session, registration_create=registration_create) - #if settings.emails_enabled and user_in.email: - # email_data = generate_new_account_email( - # email_to=user_in.email, username=user_in.email, password=user_in.password - # ) - # send_email( - # email_to=user_in.email, - # subject=email_data.subject, - # html_content=email_data.html_content, - # ) - - return registration + if is_registration_open(): + crud.create_registration( + session=session, registration_create=registration_create + ) + + return RedirectResponse("/success.html", status_code=303) + else: + return RedirectResponse("/", status_code=303) diff --git a/app/core/config.py b/app/core/config.py index a120448..3825b38 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -1,10 +1,24 @@ from pydantic_settings import BaseSettings import os +from datetime import datetime +from zoneinfo import ZoneInfo + +date_format = "%Y-%m-%dT%H:%M:%S%z" + class Settings(BaseSettings): API_V1_STR: str = "" PROJECT_NAME: str = "Choriosity Anmeldung" - SQLALCHEMY_DATABASE_URI: str = "sqlite:///" + os.environ.get("DATABASE_URL", "/data/db.sqlite") + SQLALCHEMY_DATABASE_URI: str = "sqlite:///" + os.environ.get( + "DATABASE_URL", "/data/db.sqlite" + ) + NOT_BEFORE: datetime = datetime.strptime( + os.environ.get("NOT_BEFORE", "2000-01-01T00:00:01+02:00"), date_format + ) + NOT_AFTER: datetime = datetime.strptime( + os.environ.get("NOT_AFTER", "2100-01-01T00:00:01+02:00"), date_format + ) + TZ: ZoneInfo = ZoneInfo(os.environ.get("TZ", "Europe/Berlin")) settings = Settings() diff --git a/app/core/db.py b/app/core/db.py index de82afe..86af4e6 100644 --- a/app/core/db.py +++ b/app/core/db.py @@ -9,6 +9,7 @@ engine = create_engine(str(settings.SQLALCHEMY_DATABASE_URI)) # otherwise, SQLModel might fail to initialize relationships properly # for more details: https://github.com/fastapi/full-stack-fastapi-template/issues/28 + def init_db(session: Session) -> None: # Tables should be created with Alembic migrations # But if you don't want to use migrations, create @@ -16,4 +17,4 @@ def init_db(session: Session) -> None: from sqlmodel import SQLModel # This works because the models are already imported and registered from app.models - SQLModel.metadata.create_all(engine) \ No newline at end of file + SQLModel.metadata.create_all(engine) diff --git a/app/crud.py b/app/crud.py index 846f2c6..e09e2f5 100644 --- a/app/crud.py +++ b/app/crud.py @@ -3,9 +3,11 @@ from sqlmodel import Session from app.models import Registration, RegistrationCreate -def create_registration(*, session: Session, registration_create: RegistrationCreate) -> Registration: +def create_registration( + *, session: Session, registration_create: RegistrationCreate +) -> Registration: db_obj = Registration.model_validate(registration_create) session.add(db_obj) session.commit() session.refresh(db_obj) - return db_obj \ No newline at end of file + return db_obj diff --git a/app/index.html b/app/index.html deleted file mode 100644 index cfd4d84..0000000 --- a/app/index.html +++ /dev/null @@ -1,79 +0,0 @@ - - -
-