Browse Source

Strip whitespace around username before validating

This is mostly for when people are logging in. Mobile keyboards
especially like to add a space after the username, which previously
would cause an error unless they manually deleted the trailing space.
merge-requests/55/head
Deimos 6 years ago
parent
commit
d930830b7b
  1. 11
      tildes/tildes/schemas/user.py

11
tildes/tildes/schemas/user.py

@ -92,6 +92,17 @@ class UserSchema(Schema):
if is_breached_password(value):
raise ValidationError("That password exists in a data breach (see sidebar)")
@pre_load
def prepare_username(self, data: dict) -> dict:
"""Prepare the username value before it's validated."""
if "username" not in data:
return data
# strip any leading/trailing whitespace
data["username"] = data["username"].strip()
return data
@pre_load
def prepare_email_address(self, data: dict) -> dict:
"""Prepare the email address value before it's validated."""

Loading…
Cancel
Save