imposed a filter on username that it contains only alphabets and numbers.
--- a/taskapp/views/users.py Thu Feb 04 22:14:34 2010 +0530
+++ b/taskapp/views/users.py Thu Feb 04 22:16:00 2010 +0530
@@ -50,13 +50,17 @@
if form.is_valid():
data = form.cleaned_data
if data['password'] == data['repeat_password']:
- try:
- if User.objects.get(username__exact = data['username']):
- errors=['Choose some other username']
- return render_to_response('user/register.html',{'form':form,'errors':errors})
- except:
- u = createUser(username=data['username'], email=data['email'], password=data['password'],dob = data['dob'],gender = data['gender'])
- return redirect('/accounts/login/')
+ if data['username'].isalnum():
+ try:
+ if User.objects.get(username__exact = data['username']):
+ errors=['Choose some other username']
+ return render_to_response('user/register.html',{'form':form,'errors':errors})
+ except:
+ u = createUser(username=data['username'], email=data['email'], password=data['password'],dob = data['dob'],gender = data['gender'])
+ return redirect('/accounts/login/')
+ else:
+ errors = ['Username can contain only alphabets and numbers!']
+ return render_to_response('user/register.html',{'form':form,'errors':errors})
else:
errors=['Password do not match']
form = RegistrationForm(request.POST)