Permalink
Browse files

Fixes #1

Adds basic auth interpretation to middleware.
  • Loading branch information...
1 parent 7e355d3 commit 7e21c65680b037d08deddac9d56854a7f07181c3 @tiliv tiliv committed Feb 8, 2013
Showing with 15 additions and 3 deletions.
  1. +15 −3 simple_history/middleware.py
@@ -5,9 +5,12 @@
__date__ = '2011/08/29 20:43:34'
__credits__ = ['Marty Alchin', 'Corey Bertram', 'Steven Klass']
+from base64 import b64decode
+
from django.db.models import signals
from django.utils.functional import curry
from django.utils.decorators import decorator_from_middleware
+from django.contrib.auth.models import User
from registration import FieldRegistry
@@ -18,10 +21,19 @@ def process_request(self, request):
# We aren't doing anything return..
return
- if hasattr(request, 'user') and request.user.is_authenticated:
- user = request.user
+ if 'HTTP_AUTHORIZATION' in request.META:
+ try:
+ username, password = b64decode(request.META['HTTP_AUTHORIZATION']).split(':')
+ user = User.objects.get(username=username)
+ if not user.check_password(password):
+ user = None
+ except:
+ user = None
else:
- user = None
+ if hasattr(request, 'user') and request.user.is_authenticated:
+ user = request.user
+ else:
+ user = None
update_users = curry(self.update_users, user)
signals.pre_save.connect(update_users, dispatch_uid=request, weak=False)

0 comments on commit 7e21c65

Please sign in to comment.