Skip to content

Commit 519f748

Browse files
committed
chore(auth): add username regex
1 parent 75ea4d7 commit 519f748

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

rootfs/api/models.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
from django.db import models
2+
from django.conf import settings
3+
from django.contrib.auth import validators
24
from django.contrib.auth.models import AbstractUser
35
from django.utils.translation import gettext_lazy as _
46

57
from oauth2_provider.models import AbstractApplication
68

79

810
class User(AbstractUser):
11+
username_validator = validators.UnicodeUsernameValidator(
12+
regex=settings.USERNAME_REGEX,
13+
message=_("Enter a valid username. This value may match the regex {}.".format(
14+
settings.USERNAME_REGEX
15+
))
16+
)
917
email = models.EmailField(_('email address'), unique=True)
1018

1119
@property

rootfs/api/settings/production.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,5 +399,8 @@
399399
EMAIL_USE_TLS = os.environ.get('EMAIL_USE_TLS', 'false').lower() == "true"
400400
EMAIL_USE_SSL = os.environ.get('EMAIL_USE_SSL', 'false').lower() == "true"
401401

402+
# username regex
403+
USERNAME_REGEX = os.environ.get('USERNAME_REGEX', '^[a-z][a-z0-9]{4,}$')
404+
# hcaptcha config
402405
H_CAPTCHA_KEY = os.environ.get("H_CAPTCHA_KEY")
403406
H_CAPTCHA_SECRET = os.environ.get("H_CAPTCHA_SECRET")

0 commit comments

Comments
 (0)