mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-15 07:20:17 +02:00
Merge pull request #108 from Adarnof/scrub
Validate usernames during registration.
This commit is contained in:
commit
617ac5e0f5
@ -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):
|
||||||
@ -11,7 +12,7 @@ class RegistrationForm(forms.Form):
|
|||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
if ' ' in self.cleaned_data['username']:
|
if ' ' in self.cleaned_data['username']:
|
||||||
raise forms.ValidationError(u'Username can not contain a space')
|
raise forms.ValidationError(u'Username cannot contain a space')
|
||||||
|
|
||||||
# We attempt to get the user object if we succeed we know email as been used
|
# We attempt to get the user object if we succeed we know email as been used
|
||||||
try:
|
try:
|
||||||
@ -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')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user