Scrubs usernames on registration allowing only letters, numbers and underscores.

Should prevent issue #46 from appearing on new installs.
This commit is contained in:
Adarnof 2015-11-29 01:57:35 +00:00
parent d14ec57575
commit b5a4b4980a

View File

@ -1,5 +1,6 @@
from django import forms from django import forms
from django.contrib.auth.models import User from django.contrib.auth.models import User
import re
class RegistrationForm(forms.Form): class RegistrationForm(forms.Form):
@ -20,6 +21,9 @@ class RegistrationForm(forms.Form):
except: except:
pass pass
if not re.match("^\w+$", self.cleaned_data['username']):
raise forms.ValidationError(u'Username contains illegal characters')
if 'password' in self.cleaned_data and 'password_again' in self.cleaned_data: if 'password' in self.cleaned_data and 'password_again' in self.cleaned_data:
if self.cleaned_data['password'] != self.cleaned_data['password_again']: if self.cleaned_data['password'] != self.cleaned_data['password_again']:
raise forms.ValidationError(u'Passwords do not match') raise forms.ValidationError(u'Passwords do not match')