Force lowercase usernames

parent 08580021
......@@ -5,7 +5,6 @@ import datetime
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from django.contrib.auth.forms import UserCreationForm as BaseUserCreationForm
from django.contrib.auth.models import User
from django.utils.translation import ugettext as t
from django.utils.translation import ugettext_lazy as _
......@@ -83,12 +82,8 @@ class AgeListFilter(admin.SimpleListFilter):
return queryset.filter(pk__in=users)
class UserCreationForm(BaseUserCreationForm):
class Meta(BaseUserCreationForm.Meta):
fields = ('username', 'first_name', 'last_name')
class UserAdmin(BaseUserAdmin):
form = forms.UserChangeForm
add_form = forms.UserCreationForm
actions = ['address_csv_export']
......
......@@ -37,6 +37,10 @@ class UserCreationForm(forms.ModelForm):
required=False,
initial=True)
def clean(self):
self.cleaned_data['username'] = self.cleaned_data['username'].lower()
super().clean()
def save(self, commit=True):
password = User.objects.make_random_password(length=15)
user = super().save(commit=False)
......@@ -66,3 +70,13 @@ class UserCreationForm(forms.ModelForm):
'first_name',
'last_name',
'send_welcome_email')
class UserChangeForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def clean(self):
self.cleaned_data['username'] = self.cleaned_data['username'].lower()
super().clean()
from django.contrib.auth.forms import (AuthenticationForm as
BaseAuthenticationForm)
class AuthenticationForm(BaseAuthenticationForm):
def __init__(self, request=None, *args, **kwargs):
super(AuthenticationForm, self).__init__(request, *args, **kwargs)
def clean(self):
self.cleaned_data['username'] = self.cleaned_data['username'].lower()
super().clean()
......@@ -32,6 +32,7 @@ import os.path
from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls.static import static
from django.contrib.auth.views import login
from django.contrib import admin
from django.contrib.sitemaps.views import sitemap
from django.views.generic import TemplateView
......@@ -45,6 +46,7 @@ from members.sitemaps import sitemap as members_sitemap
from partners.sitemaps import sitemap as partners_sitemap
from thabloid.sitemaps import sitemap as thabloid_sitemap
from events.sitemaps import sitemap as events_sitemap
from thaliawebsite.forms import AuthenticationForm
from utils.views import private_thumbnails, generate_thumbnail
from . import views
......@@ -107,6 +109,8 @@ urlpatterns = [
url(r'^education/', include('education.urls')),
url(r'^announcements/', include('announcements.urls')),
# Default login helpers
url(r'^login/$', login, {'authentication_form': AuthenticationForm},
name='login'),
url(r'^', include('django.contrib.auth.urls')),
url(r'^i18n/', include('django.conf.urls.i18n')),
# Sitemap
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment