Last active
August 29, 2015 14:01
-
-
Save aw3s0me/96b51f3a4329776fa65f to your computer and use it in GitHub Desktop.
Django Rest Session Authentication
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
| from rest_framework.authentication import SessionAuthentication | |
| class SuperUserAuth(SessionAuthentication): | |
| def authenticate(self, request): | |
| request = request._request | |
| user = getattr(request, 'username', None) | |
| #if not user or not user.is_active or not user.is_superuser: | |
| #return None | |
| if not username: | |
| return None | |
| try: | |
| user = User.objects.get(username=username) | |
| except User.DoesNotExist: | |
| raise exceptions.AuthenticationFailed('No such user') | |
| return (user, None) | |
| #self.enforce_csrf(request) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment