mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
Fix username-validator errors not showing in web registration form
This commit is contained in:
parent
fa552e3f57
commit
616daf723a
4 changed files with 14 additions and 30 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue