Commit e0846021 authored by Thom Wiggers's avatar Thom Wiggers 📐
Browse files

Merge branch 'feature/case-insensitive-username-login' into 'master'

Force lowercase usernames

Closes #319

See merge request !374
parents 7a817c59 67fb3ff5
......@@ -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):
def clean(self):
self.cleaned_data['username'] = self.cleaned_data['username'].lower()
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):
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()
from django.contrib.auth.forms import (AuthenticationForm as
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()
......@@ -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},
url(r'^', include('django.contrib.auth.urls')),
url(r'^i18n/', include('django.conf.urls.i18n')),
# Sitemap
Supports Markdown
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