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 16e1224ceb..6d72c9d805 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.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): """Do checks and create account""" diff --git a/evennia/settings_default.py b/evennia/settings_default.py index 38f372255f..01ea956036 100644 --- a/evennia/settings_default.py +++ b/evennia/settings_default.py @@ -34,6 +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 +# 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/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 %} diff --git a/evennia/web/utils/general_context.py b/evennia/web/utils/general_context.py index 89b097da5e..cd41d518e4 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.NEW_ACCOUNT_REGISTRATION_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, 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",