mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-01-04 08:01:22 -05:00
Fix/fix block registration (#1059)
* fix disable button * add backend env for restricting registration * update state management * add allow_signup to app info * move allow_signup to backend only * cleanup docker-compose * potential darkmode fix * fix missing variable * add banner on login page * use random bools for tests * fix initial state bug * fix state reset
This commit is contained in:
@@ -32,6 +32,8 @@ class AppSettings(BaseSettings):
|
||||
TOKEN_TIME: int = 48 # Time in Hours
|
||||
SECRET: str
|
||||
|
||||
ALLOW_SIGNUP: bool = True
|
||||
|
||||
@property
|
||||
def DOCS_URL(self) -> str | None:
|
||||
return "/docs" if self.API_DOCS else None
|
||||
@@ -119,8 +121,8 @@ def app_settings_constructor(data_dir: Path, production: bool, env_file: Path, e
|
||||
directly, but rather through this factory function.
|
||||
"""
|
||||
app_settings = AppSettings(
|
||||
_env_file=env_file,
|
||||
_env_file_encoding=env_encoding,
|
||||
_env_file=env_file, # type: ignore
|
||||
_env_file_encoding=env_encoding, # type: ignore
|
||||
**{"SECRET": determine_secrets(data_dir, production)},
|
||||
)
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ class AdminAboutController(BaseAdminController):
|
||||
db_type=settings.DB_ENGINE,
|
||||
db_url=settings.DB_URL_PUBLIC,
|
||||
default_group=settings.DEFAULT_GROUP,
|
||||
allow_signup=settings.ALLOW_SIGNUP,
|
||||
)
|
||||
|
||||
@router.get("/statistics", response_model=AppStatistics)
|
||||
|
||||
@@ -15,4 +15,5 @@ async def get_app_info():
|
||||
version=APP_VERSION,
|
||||
demo_status=settings.IS_DEMO,
|
||||
production=settings.PRODUCTION,
|
||||
allow_signup=settings.ALLOW_SIGNUP,
|
||||
)
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
from fastapi import APIRouter, status
|
||||
from fastapi import APIRouter, HTTPException, status
|
||||
|
||||
from mealie.core.config import get_app_settings
|
||||
from mealie.repos.all_repositories import get_repositories
|
||||
from mealie.routes._base import BasePublicController, controller
|
||||
from mealie.schema.response import ErrorResponse
|
||||
from mealie.schema.user.registration import CreateUserRegistration
|
||||
from mealie.schema.user.user import UserOut
|
||||
from mealie.services.user_services.registration_service import RegistrationService
|
||||
@@ -13,5 +15,12 @@ router = APIRouter(prefix="/register")
|
||||
class RegistrationController(BasePublicController):
|
||||
@router.post("", response_model=UserOut, status_code=status.HTTP_201_CREATED)
|
||||
def register_new_user(self, data: CreateUserRegistration):
|
||||
settings = get_app_settings()
|
||||
|
||||
if not settings.ALLOW_SIGNUP and data.group_token is None or data.group_token == "":
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN, detail=ErrorResponse.respond("User Registration is Disabled")
|
||||
)
|
||||
|
||||
registration_service = RegistrationService(self.deps.logger, get_repositories(self.deps.session))
|
||||
return registration_service.register_user(data)
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi_camelcase import CamelModel
|
||||
|
||||
|
||||
@@ -15,6 +13,7 @@ class AppInfo(CamelModel):
|
||||
production: bool
|
||||
version: str
|
||||
demo_status: bool
|
||||
allow_signup: bool
|
||||
|
||||
|
||||
class AdminAboutInfo(AppInfo):
|
||||
@@ -22,7 +21,7 @@ class AdminAboutInfo(AppInfo):
|
||||
api_port: int
|
||||
api_docs: bool
|
||||
db_type: str
|
||||
db_url: Path
|
||||
db_url: str | None
|
||||
default_group: str
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user