From 6fcc55a442d52c251408566f6bc924b15cef0bb3 Mon Sep 17 00:00:00 2001 From: Prabhu Ramachandran Date: Sat, 19 Nov 2011 08:38:13 +0530 Subject: ENH: Fixing login/registration forms and uname/pwd The login and registration forms are now rendered as tables which looks much nicer. The username now can take letters, digits, period and underscore. The password can take letters, digits and punctuation. --- exam/forms.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'exam') diff --git a/exam/forms.py b/exam/forms.py index 38466e8..0ae9d65 100644 --- a/exam/forms.py +++ b/exam/forms.py @@ -4,10 +4,10 @@ from exam.models import Profile from django.contrib.auth import authenticate from django.contrib.auth.models import User -from string import letters, punctuation +from string import letters, punctuation, digits -UNAME_CHARS = letters + "." -PWD_CHARS = letters + punctuation +UNAME_CHARS = letters + "._" + digits +PWD_CHARS = letters + punctuation + digits class UserRegisterForm(forms.Form): @@ -23,19 +23,20 @@ class UserRegisterForm(forms.Form): u_name = self.cleaned_data["username"] if u_name.strip(UNAME_CHARS): - raise forms.ValidationError("Only letters and period character are \ - allowed in username") + msg = "Only letters, digits, period and underscore characters are "\ + "allowed in username" + raise forms.ValidationError(msg) try: User.objects.get(username__iexact = u_name) - raise forms.ValidationError("Username already exists") + raise forms.ValidationError("Username already exists.") except User.DoesNotExist: return u_name def clean_password(self): pwd = self.cleaned_data['password'] if pwd.strip(PWD_CHARS): - raise forms.ValidationError("Only letters and punctuation are \ + raise forms.ValidationError("Only letters, digits and punctuation are \ allowed in password") return pwd -- cgit