Created
January 8, 2013 15:35
-
-
Save mjtamlyn/4484720 to your computer and use it in GitHub Desktop.
Extra work needed without https://github.com/tomchristie/django-rest-framework/pull/566
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Extra imports | |
| from rest_framework.authtoken.models import Token | |
| from rest_framework.response import Response | |
| from rest_framework import status | |
| class Login(ObtainAuthToken): | |
| serializer_class = MyAuthTokenSerializerWithExtraChecks | |
| def post(self, request): | |
| """Override the post method to use custom serializer class.""" | |
| serializer = self.serializer_class(data=request.DATA) | |
| if serializer.is_valid(): | |
| token, created = Token.objects.get_or_create(user=serializer.object['user']) | |
| return Response({'token': token.key}) | |
| return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment