Skip to content

Commit

Permalink
Use AuthTokenSerializer from django-rest-framework
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Etienne committed Jan 29, 2015
1 parent c7e7549 commit c15d6b6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 26 deletions.
24 changes: 1 addition & 23 deletions user_management/api/serializers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from django.contrib.auth import authenticate, get_user_model
from django.contrib.auth import get_user_model
from django.utils.translation import ugettext_lazy as _
from rest_framework import serializers
from rest_framework.authtoken.serializers import (
AuthTokenSerializer as DRFAuthTokenSerializer
)

from user_management.utils.validators import validate_password_strength

Expand Down Expand Up @@ -33,25 +30,6 @@ class Meta:
fields = ['email']


class AuthTokenSerializer(DRFAuthTokenSerializer):
"""
Fix DRF's error messages (which ain't very helpful).
Also, end the indentation nonsense.
"""
def validate(self, attrs):
username = attrs.get('username')
password = attrs.get('password')

user = authenticate(username=username, password=password)
if not user:
msg = _('Unable to log in with provided credentials.')
raise serializers.ValidationError(msg)

attrs['user'] = user
return attrs


class RegistrationSerializer(ValidateEmailMixin, serializers.ModelSerializer):
password = serializers.CharField(
write_only=True,
Expand Down
4 changes: 1 addition & 3 deletions user_management/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.utils.http import urlsafe_base64_decode, urlsafe_base64_encode
from django.utils.translation import ugettext_lazy as _
from incuna_mail import send
from rest_framework import generics, renderers, response, status, views
from rest_framework import generics, response, status, views
from rest_framework.authentication import get_authorization_header
from rest_framework.authtoken.views import ObtainAuthToken
from rest_framework.permissions import AllowAny, IsAuthenticated
Expand All @@ -18,8 +18,6 @@

class GetAuthToken(ObtainAuthToken):
model = models.AuthToken
renderer_classes = (renderers.JSONRenderer, renderers.BrowsableAPIRenderer)
serializer_class = serializers.AuthTokenSerializer
throttle_classes = [
throttling.UsernameLoginRateThrottle,
throttling.LoginRateThrottle,
Expand Down

0 comments on commit c15d6b6

Please sign in to comment.