Ticket #5786: form.diff
File form.diff, 3.1 KB (added by , 17 years ago) |
---|
-
django/conf/global_settings.py
335 335 336 336 LOGIN_REDIRECT_URL = '/accounts/profile/' 337 337 338 AUTH_USERNAME_PATTERN = '^\w+$' 338 339 ########### 339 340 # TESTING # 340 341 ########### -
django/contrib/auth/forms.py
6 6 from django import oldforms 7 7 from django.utils.translation import ugettext as _ 8 8 9 import re 10 from django.conf import settings 11 9 12 class UserCreationForm(oldforms.Manipulator): 10 13 "A form that creates a user, with no privileges, from the given username and password." 11 14 def __init__(self): 12 15 self.fields = ( 13 16 oldforms.TextField(field_name='username', length=30, max_length=30, is_required=True, 14 validator_list=[ validators.isAlphaNumeric,self.isValidUsername]),17 validator_list=[self.isValidUsername]), 15 18 oldforms.PasswordField(field_name='password1', length=30, max_length=60, is_required=True), 16 19 oldforms.PasswordField(field_name='password2', length=30, max_length=60, is_required=True, 17 20 validator_list=[validators.AlwaysMatchesOtherField('password1', _("The two password fields didn't match."))]), 18 21 ) 19 22 20 23 def isValidUsername(self, field_data, all_data): 24 if not re.search(getattr(settings, 'AUTH_USERNAME_PATTERN'), field_data, re.U): 25 raise validators.ValidationError, _('Username contains illegal characters.') 26 21 27 try: 22 28 User.objects.get(username=field_data) 23 29 except User.DoesNotExist: 24 return 30 return 25 31 raise validators.ValidationError, _('A user with that username already exists.') 26 32 27 33 def save(self, new_data): -
django/contrib/auth/tests.py
23 23 [] 24 24 >>> a.user_permissions.all() 25 25 [] 26 """ 27 No newline at end of file 26 >>> from django.contrib.auth.forms import * 27 >>> cf = UserCreationForm() 28 >>> cf.isValidUsername("aa", '') 29 >>> cf.isValidUsername("b!", '') 30 Traceback (most recent call last): 31 ... 32 ValidationError: [u'Username contains illegal characters.'] 33 34 """ -
docs/tutorial02.txt
359 359 filters, date-hierarchies and column-header-ordering all work together like you 360 360 think they should. 361 361 362 Customize the username pattern 363 ====================================== 364 365 Open your settings file (``mysite/settings.py``, remember) and look at the 366 ``AUTH_USERNAME_PATTERN`` setting. The default value is ''^\w+$'', which you 367 may change it to any pattern in UTF-8, for example, '^ab.*$'. 368 362 369 Customize the admin look and feel 363 370 ================================= 364 371