taskapp/views/users.py
changeset 14 54694601c5e3
parent 13 0fb64b24a1c9
child 15 4e29ed911123
--- 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)