Use snipt registration form, block emails
parent
ae85962689
commit
08d8fff0b2
4
urls.py
4
urls.py
|
@ -1,7 +1,7 @@
|
|||
from views import amazon_search, amazon_image, lexers, pro_signup, sitemap, tags, pro_signup_complete
|
||||
from django.conf.urls.defaults import include, patterns, url
|
||||
from django.views.generic.simple import direct_to_template
|
||||
from registration.forms import RegistrationFormUniqueEmail
|
||||
from utils.forms import SniptRegistrationForm
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.contrib import admin
|
||||
from snipts.views import search
|
||||
|
@ -53,7 +53,7 @@ urlpatterns = patterns('',
|
|||
url(r'^signup/$',
|
||||
'registration.views.register', {
|
||||
'backend': 'registration.backends.default.DefaultBackend',
|
||||
'form_class': RegistrationFormUniqueEmail,
|
||||
'form_class': SniptRegistrationForm,
|
||||
},
|
||||
name='registration_register'),
|
||||
url(r'', include('registration.backends.default.urls')),
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
from registration.forms import RegistrationForm
|
||||
from django.contrib.auth.models import User
|
||||
from django import forms
|
||||
|
||||
|
||||
class SniptRegistrationForm(RegistrationForm):
|
||||
"""
|
||||
Subclass of ``RegistrationForm`` which enforces uniqueness of
|
||||
email addresses.
|
||||
|
||||
"""
|
||||
def clean_username(self):
|
||||
"""
|
||||
Validate that the username is alphanumeric and is not already
|
||||
in use.
|
||||
|
||||
"""
|
||||
existing = User.objects.filter(username__iexact=self.cleaned_data['username'])
|
||||
if existing.exists():
|
||||
raise forms.ValidationError(_("A user with that username already exists."))
|
||||
|
||||
elif '@' in self.cleaned_data['username']:
|
||||
raise forms.ValidationError(_("Cannot have '@' in username."))
|
||||
elif '.' in self.cleaned_data['username']:
|
||||
raise forms.ValidationError(_("Cannot have '.' in username."))
|
||||
elif '+' in self.cleaned_data['username']:
|
||||
raise forms.ValidationError(_("Cannot have '+' in username."))
|
||||
|
||||
else:
|
||||
return self.cleaned_data['username']
|
||||
|
||||
def clean_email(self):
|
||||
"""
|
||||
Validate that the supplied email address is unique for the
|
||||
site.
|
||||
|
||||
"""
|
||||
if User.objects.filter(email__iexact=self.cleaned_data['email']):
|
||||
raise forms.ValidationError(_("This email address is already in use. Please supply a different email address."))
|
||||
return self.cleaned_data['email']
|
Loading…
Reference in New Issue