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
|
## 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
|
- Feature: Add support for saving `deque` with `maxlen` to Attributes (before
|
||||||
`maxlen` was ignored).
|
`maxlen` was ignored).
|
||||||
- Tools: More unit tests for scripts (Storsorken)
|
- 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 import timezone
|
||||||
from django.utils.module_loading import import_string
|
from django.utils.module_loading import import_string
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
from evennia.accounts.manager import AccountManager
|
from evennia.accounts.manager import AccountManager
|
||||||
from evennia.accounts.models import AccountDB
|
from evennia.accounts.models import AccountDB
|
||||||
from evennia.commands.cmdsethandler import CmdSetHandler
|
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.typeclasses.models import TypeclassBase
|
||||||
from evennia.utils import class_from_module, create, logger
|
from evennia.utils import class_from_module, create, logger
|
||||||
from evennia.utils.optionhandler import OptionHandler
|
from evennia.utils.optionhandler import OptionHandler
|
||||||
from evennia.utils.utils import (
|
from evennia.utils.utils import is_iter, lazy_property, make_iter, to_str, variable_from_module
|
||||||
is_iter,
|
|
||||||
lazy_property,
|
|
||||||
make_iter,
|
|
||||||
to_str,
|
|
||||||
variable_from_module,
|
|
||||||
)
|
|
||||||
|
|
||||||
__all__ = ("DefaultAccount", "DefaultGuest")
|
__all__ = ("DefaultAccount", "DefaultGuest")
|
||||||
|
|
||||||
|
|
@ -509,7 +502,6 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase):
|
||||||
Returns:
|
Returns:
|
||||||
validators (list): List of instantiated Validator objects.
|
validators (list): List of instantiated Validator objects.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
objs = []
|
objs = []
|
||||||
for validator in validator_config:
|
for validator in validator_config:
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ import re
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
from evennia.accounts.models import AccountDB
|
from evennia.accounts.models import AccountDB
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -24,7 +23,6 @@ class EvenniaUsernameAvailabilityValidator:
|
||||||
raises ValidationError otherwise.
|
raises ValidationError otherwise.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Check guest list
|
# Check guest list
|
||||||
if settings.GUEST_LIST and username.lower() in (
|
if settings.GUEST_LIST and username.lower() in (
|
||||||
guest.lower() for guest in settings.GUEST_LIST
|
guest.lower() for guest in settings.GUEST_LIST
|
||||||
|
|
@ -45,8 +43,7 @@ class EvenniaPasswordValidator:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
regex=r"^[\w. @+\-',]+$",
|
regex=r"^[\w. @+\-',]+$",
|
||||||
policy="Password should contain a mix of letters, "
|
policy="Password should contain a mix of letters, spaces, digits and @/./+/-/_/'/, only.",
|
||||||
"spaces, digits and @/./+/-/_/'/, only.",
|
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Constructs a standard Django password validator.
|
Constructs a standard Django password validator.
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ from django.conf import settings
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
|
|
||||||
from evennia.utils import class_from_module
|
from evennia.utils import class_from_module
|
||||||
from evennia.web.website import forms
|
from evennia.web.website import forms
|
||||||
|
|
||||||
|
|
@ -56,22 +55,16 @@ class AccountCreateView(AccountMixin, EvenniaCreateView):
|
||||||
password = form.cleaned_data["password1"]
|
password = form.cleaned_data["password1"]
|
||||||
email = form.cleaned_data.get("email", "")
|
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)
|
account, errs = self.typeclass.create(username=username, password=password, email=email)
|
||||||
|
|
||||||
# If unsuccessful, display error messages to user
|
|
||||||
if not account:
|
if not account:
|
||||||
[messages.error(self.request, err) for err in errs]
|
# password validation happens earlier, only username checks appear here.
|
||||||
|
form.add_error("username", ", ".join(errs))
|
||||||
# Call the Django "form failure" hook
|
|
||||||
return self.form_invalid(form)
|
return self.form_invalid(form)
|
||||||
|
else:
|
||||||
# Inform user of success
|
# Inform user of success
|
||||||
messages.success(
|
messages.success(
|
||||||
self.request,
|
self.request, f"Your account '{account.name}' was successfully created!"
|
||||||
"Your account '%s' was successfully created! "
|
)
|
||||||
"You may log in using it now." % account.name,
|
return HttpResponseRedirect(self.success_url)
|
||||||
)
|
|
||||||
|
|
||||||
# Redirect the user to the login page
|
|
||||||
return HttpResponseRedirect(self.success_url)
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue