diff --git a/accounts/migrations/0010_change_username_validator.py b/accounts/migrations/0010_change_username_validator.py new file mode 100644 index 0000000000000000000000000000000000000000..26f001c3e66a7b9ac6bac85cdb543f99e913b9e7 --- /dev/null +++ b/accounts/migrations/0010_change_username_validator.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.4 on 2017-04-12 08:55 +from __future__ import unicode_literals + +import django.contrib.auth.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0009_user_git_auth_token_hash'), + ] + + operations = [ + migrations.AlterField( + model_name='user', + name='username', + field=models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=30, unique=True, validators=[django.contrib.auth.validators.ASCIIUsernameValidator()], verbose_name='username'), + ), + ] diff --git a/accounts/models.py b/accounts/models.py index 915e0945b1a9ee9097e9e4b03461b990fb1218cf..51c97f38d66f1ee9290dbdbdaef9845a40ba0fbf 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -30,7 +30,7 @@ from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin from django.utils.translation import ugettext_lazy as _, pgettext_lazy from django.utils import timezone from django.contrib.auth.models import UserManager -from django.core import validators +from django.contrib.auth.validators import ASCIIUsernameValidator from course.constants import USER_STATUS_CHOICES @@ -44,13 +44,7 @@ class User(AbstractBaseUser, PermissionsMixin): unique=True, help_text=_( 'Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only.'), - validators=[ - validators.RegexValidator( - r'^[\w.@+-]+$', - _('Enter a valid username. This value may contain only ' - 'letters, numbers ' 'and @/./+/-/_ characters.') - ), - ], + validators=[ASCIIUsernameValidator()], error_messages={ 'unique': _("A user with that username already exists."), }, @@ -159,8 +153,6 @@ class User(AbstractBaseUser, PermissionsMixin): Returns the first_name plus the last_name, with a space in between. """ - if force_verbose_blank: - first_name return '%s %s' % ( verbose_blank(first_name), verbose_blank(last_name)) diff --git a/course/auth.py b/course/auth.py index 348c2e3817e3df457ed49882e3f6e5dea555e5b7..84fe455bdd1eb9473e843c23e272502be16c809e 100644 --- a/course/auth.py +++ b/course/auth.py @@ -42,7 +42,7 @@ from django.contrib.auth.forms import \ from django.contrib.sites.shortcuts import get_current_site from django.contrib.auth.decorators import user_passes_test from django.urls import reverse -from django.core import validators +from django.contrib.auth.validators import ASCIIUsernameValidator from django.utils.http import is_safe_url from django.http import HttpResponseRedirect from django.template.response import TemplateResponse @@ -386,15 +386,7 @@ def sign_in_by_user_pw(request, redirect_field_name=REDIRECT_FIELD_NAME): class SignUpForm(StyledModelForm): username = forms.CharField(required=True, max_length=30, label=_("Username"), - validators=[ - validators.RegexValidator('^[\\w.@+-]+$', - string_concat( - _('Enter a valid username.'), (' '), - _('This value may contain only letters, ' - 'numbers and @/./+/-/_ characters.') - ), - 'invalid') - ]) + validators=[ASCIIUsernameValidator()]) class Meta: model = get_user_model()