summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreliott <eliott@cactuswax.net>2007-12-26 20:20:24 +0100
committereliott <eliott@cactuswax.net>2007-12-26 20:20:24 +0100
commit6ee7a9368645c4e01de831bfdfc92ef925e9d68b (patch)
treed98bce80175bd2efc2aa9d379578b04c57fe0d23
parent6226b02f8be136a81ceff2b79b8c4280cfc5e3fb (diff)
downloadarchweb-6ee7a9368645c4e01de831bfdfc92ef925e9d68b.tar.gz
archweb-6ee7a9368645c4e01de831bfdfc92ef925e9d68b.tar.xz
initial stab at an authentication middleware
-rw-r--r--lib/sitelogin.py13
-rw-r--r--settings.py3
2 files changed, 16 insertions, 0 deletions
diff --git a/lib/sitelogin.py b/lib/sitelogin.py
new file mode 100644
index 0000000..3edec7c
--- /dev/null
+++ b/lib/sitelogin.py
@@ -0,0 +1,13 @@
+from django.contrib.auth.views import logout_then_login, login
+from django.conf import settings
+
+class SiteLogin:
+ def __init__(self):
+ self.login_path = settings.LOGIN_URL
+ def process_request(self, request):
+ if request.user.is_anonymous() and request.path != self.login_path:
+ if request.POST:
+ return login(request)
+ else:
+ return HttpResponseRedirect('%s?next=%s' % (self.login_path, request.path))
+
diff --git a/settings.py b/settings.py
index 75ea18a..c2f779d 100644
--- a/settings.py
+++ b/settings.py
@@ -40,6 +40,9 @@ ADMIN_MEDIA_PREFIX = '/admin-media/'
# URL to send users when they don't have sufficient privileges
BADPRIVS_URL = '/denied/'
+# login url
+LOGIN_URL = '/login/'
+
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.load_template_source',