Add custom validator for usernames
The default validator doesn't match every character that discord allows in usernames. I just allow all characters.
This commit is contained in:
parent
5fef17104d
commit
e871c93b4e
@ -1,5 +1,4 @@
|
|||||||
from django.contrib.auth.models import AbstractUser
|
from django.contrib.auth.models import AbstractUser
|
||||||
from django.contrib.auth.validators import UnicodeUsernameValidator
|
|
||||||
from django.db.models import CharField
|
from django.db.models import CharField
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
@ -17,6 +16,7 @@ from .utils import verify_user_data
|
|||||||
from .utils import create_error_response
|
from .utils import create_error_response
|
||||||
from .utils import create_log_success_response
|
from .utils import create_log_success_response
|
||||||
from .utils import create_success_response
|
from .utils import create_success_response
|
||||||
|
from .validators import CustomUsernameValidator
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=settings.AUTH_USER_MODEL)
|
@receiver(post_save, sender=settings.AUTH_USER_MODEL)
|
||||||
@ -35,7 +35,7 @@ class User(AbstractUser):
|
|||||||
max_length=150,
|
max_length=150,
|
||||||
unique=False,
|
unique=False,
|
||||||
help_text=_('Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.'),
|
help_text=_('Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.'),
|
||||||
validators=[UnicodeUsernameValidator()],
|
validators=[CustomUsernameValidator()],
|
||||||
)
|
)
|
||||||
id = models.CharField(max_length=30, primary_key=True)
|
id = models.CharField(max_length=30, primary_key=True)
|
||||||
discord_username = models.CharField(max_length=100, null=True)
|
discord_username = models.CharField(max_length=100, null=True)
|
||||||
|
|||||||
5
geeksbot_web/users/validators.py
Normal file
5
geeksbot_web/users/validators.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
from django.contrib.auth.validators import UnicodeUsernameValidator
|
||||||
|
|
||||||
|
|
||||||
|
class CustomUsernameValidator(UnicodeUsernameValidator):
|
||||||
|
regex = r'^[\X]+$'
|
||||||
Loading…
x
Reference in New Issue
Block a user