From 8a557ff82cd4b9147915f7aec7a7e8ae51dbcbf0 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Sun, 27 Sep 2020 09:42:01 +0300 Subject: [PATCH] Disable signups by default. The next commit includes README instructions on how to create users and enable signups. --- django_etebase/utils.py | 6 ++++++ etebase_server/settings.py | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/django_etebase/utils.py b/django_etebase/utils.py index 08f81ae..1351f9b 100644 --- a/django_etebase/utils.py +++ b/django_etebase/utils.py @@ -1,4 +1,6 @@ from django.contrib.auth import get_user_model +from django.core.exceptions import PermissionDenied + from . import app_settings @@ -18,3 +20,7 @@ def create_user(*args, **kwargs): return custom_func(*args, **kwargs) _ = kwargs.pop('view') return User.objects.create_user(*args, **kwargs) + + +def create_user_blocked(*args, **kwargs): + raise PermissionDenied('Signup is disabled for this server. Please refer to the README for more information.') diff --git a/etebase_server/settings.py b/etebase_server/settings.py index 7af0c60..f785cb7 100644 --- a/etebase_server/settings.py +++ b/etebase_server/settings.py @@ -29,7 +29,7 @@ AUTH_USER_MODEL = 'myauth.User' SECRET_FILE = os.path.join(BASE_DIR, "secret.txt") # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = False +DEBUG = True ALLOWED_HOSTS = [] @@ -167,6 +167,7 @@ if any(os.path.isfile(x) for x in config_locations): ETEBASE_API_PERMISSIONS = ('rest_framework.permissions.IsAuthenticated', ) ETEBASE_API_AUTHENTICATORS = ('django_etebase.token_auth.authentication.TokenAuthentication', 'rest_framework.authentication.SessionAuthentication') +ETEBASE_CREATE_USER_FUNC = 'django_etebase.utils.create_user_blocked' # Make an `etebase_server_settings` module available to override settings. try: