mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 06:42:16 +00:00
New Registration form that blocks bad domains
This commit is contained in:
@@ -151,6 +151,10 @@ HR_STAFF_GROUP = 'HR Staff'
|
||||
FULL_API_USER_ID = 415631
|
||||
FULL_API_CHARACTER_ID = 246102445
|
||||
|
||||
## Email Registration
|
||||
|
||||
BANNED_EMAIL_DOMAINS = ['att.net']
|
||||
|
||||
# try and import local settings
|
||||
try:
|
||||
from settingslocal import *
|
||||
|
||||
22
sso/forms.py
22
sso/forms.py
@@ -7,7 +7,29 @@ import settings
|
||||
from eve_api.models.api_player import EVEAccount, EVEPlayerCharacter, EVEPlayerCorporation
|
||||
from sso.models import ServiceAccount, Service
|
||||
from reddit.models import RedditAccount
|
||||
from registration.forms import RegistrationForm
|
||||
from settings import BANNED_EMAIL_DOMAINS
|
||||
|
||||
class RegistrationFormUniqueEmailBlocked(RegistrationForm):
|
||||
"""
|
||||
Subclass of ``RegistrationForm`` which disallows registration from certain domains
|
||||
and also makes sure that the email address is unique in the DB
|
||||
"""
|
||||
|
||||
def clean_email(self):
|
||||
"""
|
||||
Check the supplied email address against a list of known free
|
||||
webmail domains.
|
||||
"""
|
||||
|
||||
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']
|
||||
|
||||
email_domain = self.cleaned_data['email'].split('@')[1]
|
||||
if email_domain in BANNED_EMAIL_DOMAINS:
|
||||
raise forms.ValidationError(_("Your email provider (%s) is banned from registering, please use a different address."))
|
||||
return self.cleaned_data['email']
|
||||
|
||||
class EveAPIForm(forms.Form):
|
||||
""" EVE API input form """
|
||||
|
||||
4
urls.py
4
urls.py
@@ -4,12 +4,12 @@ from django.contrib.auth.views import login
|
||||
import settings
|
||||
|
||||
from registration.views import register
|
||||
from registration.forms import RegistrationFormUniqueEmail
|
||||
from sso.forms import RegistrationFormUniqueEmailBlocked
|
||||
|
||||
admin.autodiscover()
|
||||
|
||||
urlpatterns = patterns('',
|
||||
(r'^register/$', register, {'form_class' :RegistrationFormUniqueEmail }),
|
||||
(r'^register/$', register, {'form_class': RegistrationFormUniqueEmailBlocked}),
|
||||
(r'^admin/', include(admin.site.urls)),
|
||||
('', include('registration.urls')),
|
||||
('', include('sso.urls')),
|
||||
|
||||
Reference in New Issue
Block a user