Last active
August 29, 2015 14:28
-
-
Save mkouhei/0dd5dfa29df5c5ed6d69 to your computer and use it in GitHub Desktop.
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
| # -*- coding: utf-8 -*- | |
| from django.contrib.auth import authenticate, login | |
| from django.http import HttpResponseRedirect | |
| from django.conf import settings | |
| class CustomAuthMiddleware(object): | |
| def process_request(self, request): | |
| _token = None | |
| if request.META.get('HTTP_X_AUTH_TOKEN'): | |
| _token = request.META.get('HTTP_X_AUTH_TOKEN') | |
| if request.method == 'POST' and request.POST.get('auth_token'): | |
| _token = request.POST['auth_token'] | |
| if _token: | |
| user = authenticate(auth_token=_token) | |
| if user is not None: | |
| request.user = user | |
| login(request, user) | |
| if not request.META.get('HTTP_X_AUTH_TOKEN'): | |
| return HttpResponseRedirect(settings.LOGIN_REDIRECT_URL) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment