mirror of
https://github.com/etesync/server
synced 2024-12-27 09:48:24 +00:00
Username: disallow @ in usernames.
This commit is contained in:
parent
e9e77945a6
commit
4083be8e8c
19
myauth/migrations/0002_auto_20200515_0801.py
Normal file
19
myauth/migrations/0002_auto_20200515_0801.py
Normal file
@ -0,0 +1,19 @@
|
||||
# Generated by Django 3.0.3 on 2020-05-15 08:01
|
||||
|
||||
from django.db import migrations, models
|
||||
import myauth.models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('myauth', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='user',
|
||||
name='username',
|
||||
field=models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and ./+/-/_ only.', max_length=150, unique=True, validators=[myauth.models.UnicodeUsernameValidator()], verbose_name='username'),
|
||||
),
|
||||
]
|
@ -1,5 +1,30 @@
|
||||
from django.contrib.auth.models import AbstractUser
|
||||
from django.core import validators
|
||||
from django.db import models
|
||||
from django.utils.deconstruct import deconstructible
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
@deconstructible
|
||||
class UnicodeUsernameValidator(validators.RegexValidator):
|
||||
regex = r'^[\w.+-]+\Z'
|
||||
message = _(
|
||||
'Enter a valid username. This value may contain only letters, '
|
||||
'numbers, and ./+/-/_ characters.'
|
||||
)
|
||||
flags = 0
|
||||
|
||||
|
||||
class User(AbstractUser):
|
||||
pass
|
||||
username_validator = UnicodeUsernameValidator()
|
||||
|
||||
username = models.CharField(
|
||||
_('username'),
|
||||
max_length=150,
|
||||
unique=True,
|
||||
help_text=_('Required. 150 characters or fewer. Letters, digits and ./+/-/_ only.'),
|
||||
validators=[username_validator],
|
||||
error_messages={
|
||||
'unique': _("A user with that username already exists."),
|
||||
},
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user