mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-04 02:49:15 +02:00
Apply restrictions to username characters during signup
This commit is contained in:
parent
dcd33693e5
commit
ba76fe9f49
5 changed files with 39 additions and 1 deletions
|
@ -1,8 +1,13 @@
|
|||
import re
|
||||
|
||||
from django.conf import settings
|
||||
from django.core import validators
|
||||
from django.utils.deconstruct import deconstructible
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from rest_auth.serializers import PasswordResetSerializer as PRS
|
||||
from rest_auth.registration.serializers import RegisterSerializer as RS
|
||||
from rest_framework import serializers
|
||||
|
||||
from versatileimagefield.serializers import VersatileImageFieldSerializer
|
||||
|
||||
from funkwhale_api.activity import serializers as activity_serializers
|
||||
|
@ -10,6 +15,19 @@ from funkwhale_api.activity import serializers as activity_serializers
|
|||
from . import models
|
||||
|
||||
|
||||
@deconstructible
|
||||
class ASCIIUsernameValidator(validators.RegexValidator):
|
||||
regex = r"^[\w]+$"
|
||||
message = _(
|
||||
"Enter a valid username. This value may contain only English letters, "
|
||||
"numbers, and _ characters."
|
||||
)
|
||||
flags = re.ASCII
|
||||
|
||||
|
||||
username_validators = [ASCIIUsernameValidator()]
|
||||
|
||||
|
||||
class RegisterSerializer(RS):
|
||||
invitation = serializers.CharField(
|
||||
required=False, allow_null=True, allow_blank=True
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue