Commit 41d1f199 authored by Christophe Henry's avatar Christophe Henry

feat: disallow usage of '@' in usernames (startinblox/applications/sib-app#245)

parent a4955c68
Pipeline #6172 passed with stage
in 27 seconds
# -*- coding: utf-8 -*-
# Generated by Django 1.11.25 on 2019-10-24 08:54
from __future__ import unicode_literals
from django.db import migrations, models
import djangoldp_account.models
class Migration(migrations.Migration):
dependencies = [
('djangoldp_account', '0002_auto_20190917_1141'),
]
operations = [
migrations.AlterField(
model_name='ldpuser',
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=[djangoldp_account.models.UsernameValidator()], verbose_name='username'),
),
]
import re
import validators
from django.conf import settings
from django.core.validators import validate_email
from django.core.validators import RegexValidator
from django.contrib.auth.models import AbstractUser
from django.db import models
from importlib import import_module
from django.db.models.signals import post_save, pre_save
from django.dispatch import receiver
from django.urls import reverse_lazy
from django.utils.deconstruct import deconstructible
from django.utils.translation import ugettext_lazy as _
from importlib import import_module
from djangoldp.models import Model
......@@ -30,8 +32,29 @@ s_fields.extend(user_fields)
s_fields.extend(user_nested_fields)
@deconstructible
class UsernameValidator(RegexValidator):
regex = r'^[\w.+-]+$'
message = _(
'Enter a valid username. This value may contain only letters, '
'numbers, and ./+/-/_ characters.'
)
flags = re.UNICODE
class LDPUser(AbstractUser, Model):
slug = models.SlugField(unique=True, blank=True, null=True)
username_validator = UsernameValidator()
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."),
},
)
class Meta:
verbose_name = _('user')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment