Lower case username in token API

parent 8c3c53e9
...@@ -8,13 +8,21 @@ from django.db.models import Q ...@@ -8,13 +8,21 @@ from django.db.models import Q
from django.http import HttpResponse from django.http import HttpResponse
from django.shortcuts import get_object_or_404, render from django.shortcuts import get_object_or_404, render
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
from rest_framework.authtoken.views import ObtainAuthToken
from members.services import member_achievements from .services import member_achievements
from members.models import Member
from . import models from . import models
from .forms import ProfileForm from .forms import ProfileForm
class ObtainThaliaAuthToken(ObtainAuthToken):
def post(self, request, *args, **kwargs):
request._data = request.POST.copy()
request.POST['username'] = request.POST.get('username').lower()
return super().post(request, *args, **kwargs)
def filter_users(tab, keywords, year_range): def filter_users(tab, keywords, year_range):
memberships_query = Q(until__gt=datetime.now()) | Q(until=None) memberships_query = Q(until__gt=datetime.now()) | Q(until=None)
members_query = ~Q(id=None) members_query = ~Q(id=None)
...@@ -54,7 +62,7 @@ def filter_users(tab, keywords, year_range): ...@@ -54,7 +62,7 @@ def filter_users(tab, keywords, year_range):
else: else:
memberships = models.Membership.objects.filter(memberships_query) memberships = models.Membership.objects.filter(memberships_query)
members_query &= Q(pk__in=memberships.values('user__pk')) members_query &= Q(pk__in=memberships.values('user__pk'))
return (Member.objects return (models.Member.objects
.filter(members_query) .filter(members_query)
.order_by('-profile__starting_year', .order_by('-profile__starting_year',
'first_name')) 'first_name'))
...@@ -112,7 +120,7 @@ def index(request): ...@@ -112,7 +120,7 @@ def index(request):
@login_required @login_required
def profile(request, pk=None): def profile(request, pk=None):
if pk: if pk:
member = get_object_or_404(Member, pk=int(pk)) member = get_object_or_404(models.Member, pk=int(pk))
else: else:
member = request.member member = request.member
...@@ -165,11 +173,11 @@ def iban_export(request): ...@@ -165,11 +173,11 @@ def iban_export(request):
header_fields = ['name', 'username', 'iban'] header_fields = ['name', 'username', 'iban']
rows = [] rows = []
members = Member.active_members.filter( members = models.Member.active_members.filter(
profile__direct_debit_authorized=True) profile__direct_debit_authorized=True)
for member in members: for member in members:
if (member.current_membership.type != 'honorary'): if member.current_membership.type != 'honorary':
rows.append({ rows.append({
'name': member.get_full_name(), 'name': member.get_full_name(),
'username': member.username, 'username': member.username,
...@@ -193,7 +201,7 @@ def statistics(request): ...@@ -193,7 +201,7 @@ def statistics(request):
member_types = ("member", "supporter", "honorary") member_types = ("member", "supporter", "honorary")
# The numbers # The numbers
total = Member.active_members.count() total = models.Member.active_members.count()
context = { context = {
"total_members": total, "total_members": total,
......
...@@ -38,14 +38,13 @@ from django.contrib.auth.views import login ...@@ -38,14 +38,13 @@ from django.contrib.auth.views import login
from django.contrib.sitemaps.views import sitemap from django.contrib.sitemaps.views import sitemap
from django.views.generic import TemplateView from django.views.generic import TemplateView
from django.views.i18n import JavaScriptCatalog from django.views.i18n import JavaScriptCatalog
from rest_framework.authtoken import views as rfviews
import members import members
import registrations
from activemembers.sitemaps import sitemap as activemembers_sitemap from activemembers.sitemaps import sitemap as activemembers_sitemap
from documents.sitemaps import sitemap as documents_sitemap from documents.sitemaps import sitemap as documents_sitemap
from events.sitemaps import sitemap as events_sitemap from events.sitemaps import sitemap as events_sitemap
from members.sitemaps import sitemap as members_sitemap from members.sitemaps import sitemap as members_sitemap
from members.views import ObtainAuthToken, ObtainThaliaAuthToken
from partners.sitemaps import sitemap as partners_sitemap from partners.sitemaps import sitemap as partners_sitemap
from thabloid.sitemaps import sitemap as thabloid_sitemap from thabloid.sitemaps import sitemap as thabloid_sitemap
from thaliawebsite.forms import AuthenticationForm from thaliawebsite.forms import AuthenticationForm
...@@ -99,7 +98,7 @@ urlpatterns = [ ...@@ -99,7 +98,7 @@ urlpatterns = [
url(r'^api/', include([ url(r'^api/', include([
url(r'wikilogin', views.wiki_login), url(r'wikilogin', views.wiki_login),
url(r'^v1/', include([ url(r'^v1/', include([
url(r'^token-auth', rfviews.obtain_auth_token), url(r'^token-auth', ObtainThaliaAuthToken.as_view()),
url(r'^', include('events.api.urls')), url(r'^', include('events.api.urls')),
url(r'^', include('members.api.urls')), url(r'^', include('members.api.urls')),
url(r'^', include('partners.api.urls')), url(r'^', include('partners.api.urls')),
......
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