imposed a filter on username that it contains only alphabets and numbers.
authoranoop
Fri, 29 Jan 2010 22:11:43 +0530
changeset 7 232d40a28118
parent 6 94136f9a48bc
child 8 825a497d95b0
imposed a filter on username that it contains only alphabets and numbers.
pytask/taskapp/views/users.py
--- a/pytask/taskapp/views/users.py	Fri Jan 29 21:37:13 2010 +0530
+++ b/pytask/taskapp/views/users.py	Fri Jan 29 22:11:43 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)