From 04e036978cbf92d8e6b7b9448f06a74e8e6587c4 Mon Sep 17 00:00:00 2001 From: InspectorCaracal Date: Sat, 17 Dec 2022 14:06:18 -0700 Subject: [PATCH 1/4] registration setting --- evennia/commands/default/unloggedin.py | 9 ++++ evennia/settings_default.py | 2 + evennia/web/templates/website/_menu.html | 8 ++-- .../website/registration/register.html | 43 ++++++++++--------- 4 files changed, 39 insertions(+), 23 deletions(-) diff --git a/evennia/commands/default/unloggedin.py b/evennia/commands/default/unloggedin.py index 16e1224ceb..e92a52f3f5 100644 --- a/evennia/commands/default/unloggedin.py +++ b/evennia/commands/default/unloggedin.py @@ -172,6 +172,15 @@ class CmdUnconnectedCreate(COMMAND_DEFAULT_CLASS): locks = "cmd:all()" arg_regex = r"\s.*?|$" + def at_pre_cmd(self): + """Verify that account creation is enabled.""" + if not settings.REGISTER_ENABLED: + # truthy return cancels the command + self.msg("Registration is currently disabled.") + return True + + return super().at_pre_cmd() + def func(self): """Do checks and create account""" diff --git a/evennia/settings_default.py b/evennia/settings_default.py index 38f372255f..a6d8c626a4 100644 --- a/evennia/settings_default.py +++ b/evennia/settings_default.py @@ -34,6 +34,8 @@ SERVER_HOSTNAME = "localhost" # Lockdown mode will cut off the game from any external connections # and only allow connections from localhost. Requires a cold reboot. LOCKDOWN_MODE = False +# Enables new account registration +REGISTER_ENABLED = True # Activate telnet service TELNET_ENABLED = True # A list of ports the Evennia telnet server listens on Can be one or many. diff --git a/evennia/web/templates/website/_menu.html b/evennia/web/templates/website/_menu.html index cbf8c00812..72fe89de02 100644 --- a/evennia/web/templates/website/_menu.html +++ b/evennia/web/templates/website/_menu.html @@ -78,9 +78,11 @@ folder and edit it to add/remove links to the menu.
  • Log In
  • -
  • - Register -
  • + {% if register_enabled %} +
  • + Register +
  • + {% endif %} {% endif %} {% endblock %} diff --git a/evennia/web/templates/website/registration/register.html b/evennia/web/templates/website/registration/register.html index 5475d922be..f54d75054d 100644 --- a/evennia/web/templates/website/registration/register.html +++ b/evennia/web/templates/website/registration/register.html @@ -27,26 +27,29 @@ Register {% endif %} {% if not user.is_authenticated %} -
    - {% csrf_token %} - - {% for field in form %} -
    - {{ field.label_tag }} - {{ field | addclass:"form-control" }} - {% if field.help_text %} - {{ field.help_text|safe }} - {% endif %} -
    - {% endfor %} - -
    -
    - - -
    -
    - + {% if register_enabled %} +
    + {% csrf_token %} + + {% for field in form %} +
    + {{ field.label_tag }} + {{ field | addclass:"form-control" }} + {% if field.help_text %} + {{ field.help_text|safe }} + {% endif %} +
    + {% endfor %} + +
    +
    + + +
    +
    + {% else %} +

    Registration is currently disabled.

    + {% endif %} {% endif %} From edc212f1ffed632a26df2319db6bc92f21dfa96f Mon Sep 17 00:00:00 2001 From: InspectorCaracal <51038201+InspectorCaracal@users.noreply.github.com> Date: Mon, 2 Jan 2023 18:52:16 -0700 Subject: [PATCH 2/4] add registration setting to context --- evennia/web/utils/general_context.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/evennia/web/utils/general_context.py b/evennia/web/utils/general_context.py index 89b097da5e..5b3f172cba 100644 --- a/evennia/web/utils/general_context.py +++ b/evennia/web/utils/general_context.py @@ -22,6 +22,8 @@ GAME_SLOGAN = None SERVER_VERSION = None SERVER_HOSTNAME = None +REGISTER_ENABLED = None + TELNET_ENABLED = None TELNET_PORTS = None TELNET_SSL_ENABLED = None @@ -50,6 +52,7 @@ def load_game_settings(): """ global GAME_NAME, GAME_SLOGAN, SERVER_VERSION, SERVER_HOSTNAME + global REGISTER_ENABLED global TELNET_ENABLED, TELNET_PORTS global TELNET_SSL_ENABLED, TELNET_SSL_PORTS global SSH_ENABLED, SSH_PORTS @@ -67,6 +70,8 @@ def load_game_settings(): GAME_SLOGAN = SERVER_VERSION SERVER_HOSTNAME = settings.SERVER_HOSTNAME + REGISTER_ENABLED = settings.REGISTER_ENABLED + TELNET_ENABLED = settings.TELNET_ENABLED TELNET_PORTS = settings.TELNET_PORTS TELNET_SSL_ENABLED = settings.SSL_ENABLED @@ -119,6 +124,7 @@ def general_context(request): "evennia_setupapps": GAME_SETUP, "evennia_connectapps": CONNECTIONS, "evennia_websiteapps": WEBSITE, + "register_enabled": REGISTER_ENABLED, "telnet_enabled": TELNET_ENABLED, "telnet_ports": TELNET_PORTS, "telnet_ssl_enabled": TELNET_SSL_ENABLED, From 0b12e2827f321ba21e1b7810e88347050ee75338 Mon Sep 17 00:00:00 2001 From: InspectorCaracal Date: Mon, 2 Jan 2023 21:42:03 -0700 Subject: [PATCH 3/4] update test --- evennia/web/utils/tests.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/evennia/web/utils/tests.py b/evennia/web/utils/tests.py index 848919ee39..ad70fb882e 100644 --- a/evennia/web/utils/tests.py +++ b/evennia/web/utils/tests.py @@ -10,6 +10,7 @@ class TestGeneralContext(TestCase): @patch("evennia.web.utils.general_context.GAME_NAME", "test_name") @patch("evennia.web.utils.general_context.GAME_SLOGAN", "test_game_slogan") + @patch("evennia.web.utils.general_context.REGISTER_ENABLED", "register_enabled_testvalue") @patch( "evennia.web.utils.general_context.WEBSOCKET_CLIENT_ENABLED", "websocket_client_enabled_testvalue", @@ -37,6 +38,7 @@ class TestGeneralContext(TestCase): "evennia_setupapps": ["Permissions", "Config"], "evennia_connectapps": ["Irc"], "evennia_websiteapps": ["Flatpages", "News", "Sites"], + "register_enabled": "register_enabled_testvalue", "webclient_enabled": "webclient_enabled_testvalue", "websocket_enabled": "websocket_client_enabled_testvalue", "websocket_port": "websocket_client_port_testvalue", From 07af134027d34c1158c9f0785a9156b09318b372 Mon Sep 17 00:00:00 2001 From: InspectorCaracal Date: Fri, 6 Jan 2023 11:37:24 -0700 Subject: [PATCH 4/4] update setting name, tests --- evennia/commands/default/tests.py | 8 ++++++++ evennia/commands/default/unloggedin.py | 4 ++-- evennia/settings_default.py | 5 +++-- evennia/web/utils/general_context.py | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/evennia/commands/default/tests.py b/evennia/commands/default/tests.py index 051a0e1976..dccc124520 100644 --- a/evennia/commands/default/tests.py +++ b/evennia/commands/default/tests.py @@ -2115,6 +2115,14 @@ class TestUnconnectedCommand(BaseEvenniaCommandTest): self.call(unloggedin.CmdUnconnectedInfo(), "", expected) del gametime.SERVER_START_TIME + @override_settings(NEW_ACCOUNT_REGISTRATION_ENABLED=False) + def test_disabled_registration(self): + self.call( + unloggedin.CmdUnconnectedCreate(), + "testacct testpass", + "Registration is currently disabled.", + ) + # Test syscommands diff --git a/evennia/commands/default/unloggedin.py b/evennia/commands/default/unloggedin.py index e92a52f3f5..6d72c9d805 100644 --- a/evennia/commands/default/unloggedin.py +++ b/evennia/commands/default/unloggedin.py @@ -174,11 +174,11 @@ class CmdUnconnectedCreate(COMMAND_DEFAULT_CLASS): def at_pre_cmd(self): """Verify that account creation is enabled.""" - if not settings.REGISTER_ENABLED: + if not settings.NEW_ACCOUNT_REGISTRATION_ENABLED: # truthy return cancels the command self.msg("Registration is currently disabled.") return True - + return super().at_pre_cmd() def func(self): diff --git a/evennia/settings_default.py b/evennia/settings_default.py index a6d8c626a4..01ea956036 100644 --- a/evennia/settings_default.py +++ b/evennia/settings_default.py @@ -34,8 +34,9 @@ SERVER_HOSTNAME = "localhost" # Lockdown mode will cut off the game from any external connections # and only allow connections from localhost. Requires a cold reboot. LOCKDOWN_MODE = False -# Enables new account registration -REGISTER_ENABLED = True +# Controls whether new account registration is available. +# Set to False to lock down the registration page and the create account command. +NEW_ACCOUNT_REGISTRATION_ENABLED = True # Activate telnet service TELNET_ENABLED = True # A list of ports the Evennia telnet server listens on Can be one or many. diff --git a/evennia/web/utils/general_context.py b/evennia/web/utils/general_context.py index 5b3f172cba..cd41d518e4 100644 --- a/evennia/web/utils/general_context.py +++ b/evennia/web/utils/general_context.py @@ -70,7 +70,7 @@ def load_game_settings(): GAME_SLOGAN = SERVER_VERSION SERVER_HOSTNAME = settings.SERVER_HOSTNAME - REGISTER_ENABLED = settings.REGISTER_ENABLED + REGISTER_ENABLED = settings.NEW_ACCOUNT_REGISTRATION_ENABLED TELNET_ENABLED = settings.TELNET_ENABLED TELNET_PORTS = settings.TELNET_PORTS