From 43e31abc8d0dbec01859d03515954750c0b75ab9 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sun, 25 Feb 2024 17:54:11 +0100 Subject: [PATCH] Update login contribs to honor ACCOUNT_REGISTRATION_ENABLED. Resolve #3428 --- CHANGELOG.md | 2 ++ evennia/commands/default/unloggedin.py | 3 +-- .../contrib/base_systems/email_login/email_login.py | 10 +++++++++- .../contrib/base_systems/menu_login/menu_login.py | 13 ++++++------- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f7c9fbc22..3287504a70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,8 @@ (InspectorCaracal) - [Fix][pull3434]: Adjust lunr search weights to void clashing of cmd-aliases over keys which caused some help entries to shadow others (InspectorCaracal) +- Fix: Make `menu/email_login` contribs honor `NEW_ACCOUNT_REGISTRATION_ENABLED` + setting (Griatch) - Doc fixes (InspectorCaracal, Griatch) [new-ondemandhandler][https://www.evennia.com/docs/latest/Components/OnDemandHandler.html] diff --git a/evennia/commands/default/unloggedin.py b/evennia/commands/default/unloggedin.py index 75fff10ccd..4071cc027f 100644 --- a/evennia/commands/default/unloggedin.py +++ b/evennia/commands/default/unloggedin.py @@ -6,9 +6,8 @@ import datetime import re from codecs import lookup as codecs_lookup -from django.conf import settings - import evennia +from django.conf import settings from evennia.commands.cmdhandler import CMD_LOGINSTART from evennia.comms.models import ChannelDB from evennia.utils import class_from_module, create, gametime, logger, utils diff --git a/evennia/contrib/base_systems/email_login/email_login.py b/evennia/contrib/base_systems/email_login/email_login.py index 8b84b6459e..ed2d94e8d4 100644 --- a/evennia/contrib/base_systems/email_login/email_login.py +++ b/evennia/contrib/base_systems/email_login/email_login.py @@ -33,7 +33,6 @@ the module given by settings.CONNECTION_SCREEN_MODULE. """ from django.conf import settings - from evennia.accounts.models import AccountDB from evennia.commands.cmdhandler import CMD_LOGINSTART from evennia.commands.cmdset import CmdSet @@ -142,6 +141,15 @@ class CmdUnconnectedCreate(MuxCommand): aliases = ["cre", "cr"] locks = "cmd:all()" + 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 parse(self): """ The parser must handle the multiple-word account diff --git a/evennia/contrib/base_systems/menu_login/menu_login.py b/evennia/contrib/base_systems/menu_login/menu_login.py index 98c560186e..b34db8683a 100644 --- a/evennia/contrib/base_systems/menu_login/menu_login.py +++ b/evennia/contrib/base_systems/menu_login/menu_login.py @@ -11,7 +11,7 @@ To install, add these lines to the settings file (`mygame/server/conf/settings.p CMDSET_UNLOGGEDIN = "evennia.contrib.base_systems.menu_login.UnloggedinCmdSet" CONNECTION_SCREEN_MODULE = "evennia.contrib.base_systems.menu_login.connection_screens" -Reload the server and the new connection method will be active. If you want to modify the +Reload the server and the new connection method will be active. If you want to modify the way the connection screen looks, use the current one as a guide and create a new one in your game folder. Then update the settings file CONNECTION_SCREEN_MODULE to point to yours. @@ -21,14 +21,9 @@ called automatically when a new user connects. """ from django.conf import settings - from evennia import CmdSet, Command, syscmdkeys from evennia.utils.evmenu import EvMenu -from evennia.utils.utils import ( - callables_from_module, - class_from_module, - random_string_from_module, -) +from evennia.utils.utils import callables_from_module, class_from_module, random_string_from_module _CONNECTION_SCREEN_MODULE = settings.CONNECTION_SCREEN_MODULE _GUEST_ENABLED = settings.GUEST_ENABLED @@ -90,6 +85,10 @@ def node_enter_username(caller, raw_text, **kwargs): else: new_user = False + if new_user and not settings.ACCOUNT_REGISTRATION_ENABLED: + caller.msg("Registration is currently disabled.") + return None + # pass username/new_user into next node as kwargs return "node_enter_password", {"new_user": new_user, "username": username}