diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e75fcdd06..f1a047ae00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,9 @@ ## Main branch -- Feature: Better ANSI color fallbacks (InspectorCaracal) +- Fix: The username validator did not display errors correctly in web + registration form. +- Feature: Better ANSI color fallbacks (InspectorCaracal). - Feature: Add support for saving `deque` with `maxlen` to Attributes (before `maxlen` was ignored). - Tools: More unit tests for scripts (Storsorken) diff --git a/evennia/accounts/accounts.py b/evennia/accounts/accounts.py index 1a46cdbc19..3c1708c72d 100644 --- a/evennia/accounts/accounts.py +++ b/evennia/accounts/accounts.py @@ -20,7 +20,6 @@ from django.core.exceptions import ImproperlyConfigured, ValidationError from django.utils import timezone from django.utils.module_loading import import_string from django.utils.translation import gettext as _ - from evennia.accounts.manager import AccountManager from evennia.accounts.models import AccountDB from evennia.commands.cmdsethandler import CmdSetHandler @@ -38,13 +37,7 @@ from evennia.typeclasses.attributes import ModelAttributeBackend, NickHandler from evennia.typeclasses.models import TypeclassBase from evennia.utils import class_from_module, create, logger from evennia.utils.optionhandler import OptionHandler -from evennia.utils.utils import ( - is_iter, - lazy_property, - make_iter, - to_str, - variable_from_module, -) +from evennia.utils.utils import is_iter, lazy_property, make_iter, to_str, variable_from_module __all__ = ("DefaultAccount", "DefaultGuest") @@ -509,7 +502,6 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase): Returns: validators (list): List of instantiated Validator objects. """ - objs = [] for validator in validator_config: try: diff --git a/evennia/server/validators.py b/evennia/server/validators.py index f03ce0b161..234a52fbef 100644 --- a/evennia/server/validators.py +++ b/evennia/server/validators.py @@ -3,7 +3,6 @@ import re from django.conf import settings from django.core.exceptions import ValidationError from django.utils.translation import gettext as _ - from evennia.accounts.models import AccountDB @@ -24,7 +23,6 @@ class EvenniaUsernameAvailabilityValidator: raises ValidationError otherwise. """ - # Check guest list if settings.GUEST_LIST and username.lower() in ( guest.lower() for guest in settings.GUEST_LIST @@ -45,8 +43,7 @@ class EvenniaPasswordValidator: def __init__( self, regex=r"^[\w. @+\-',]+$", - policy="Password should contain a mix of letters, " - "spaces, digits and @/./+/-/_/'/, only.", + policy="Password should contain a mix of letters, spaces, digits and @/./+/-/_/'/, only.", ): """ Constructs a standard Django password validator. diff --git a/evennia/web/website/views/accounts.py b/evennia/web/website/views/accounts.py index 4964d3d567..70a811dee7 100644 --- a/evennia/web/website/views/accounts.py +++ b/evennia/web/website/views/accounts.py @@ -8,7 +8,6 @@ from django.conf import settings from django.contrib import messages from django.http import HttpResponseRedirect from django.urls import reverse_lazy - from evennia.utils import class_from_module from evennia.web.website import forms @@ -56,22 +55,16 @@ class AccountCreateView(AccountMixin, EvenniaCreateView): password = form.cleaned_data["password1"] email = form.cleaned_data.get("email", "") - # Create account + # Create account. This also runs all validations on the username/password. account, errs = self.typeclass.create(username=username, password=password, email=email) - # If unsuccessful, display error messages to user if not account: - [messages.error(self.request, err) for err in errs] - - # Call the Django "form failure" hook + # password validation happens earlier, only username checks appear here. + form.add_error("username", ", ".join(errs)) return self.form_invalid(form) - - # Inform user of success - messages.success( - self.request, - "Your account '%s' was successfully created! " - "You may log in using it now." % account.name, - ) - - # Redirect the user to the login page - return HttpResponseRedirect(self.success_url) + else: + # Inform user of success + messages.success( + self.request, f"Your account '{account.name}' was successfully created!" + ) + return HttpResponseRedirect(self.success_url)