1
0
mirror of https://github.com/etesync/server synced 2024-12-29 10:48:07 +00:00
etesync-server/myauth/models.py

31 lines
909 B
Python
Raw Normal View History

from django.contrib.auth.models import AbstractUser
2020-05-15 08:01:56 +00:00
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):
2020-05-15 08:01:56 +00:00
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."),
},
)