aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsk Solem <askh@modwheel.net>2009-03-17 16:01:15 +0100
committerAsk Solem Hoel <askh@opera.com>2009-03-17 16:01:15 +0100
commitfe01b7f71fe925965c0ebc0cd7c875323760372d (patch)
tree08b39ea216acfd0cb6dfa7a0ba82ac68cb4555dc
parent836f683018aec80a4842109deb78800f28e3c8cd (diff)
downloadchishop-fe01b7f71fe925965c0ebc0cd7c875323760372d.tar.bz2
chishop-fe01b7f71fe925965c0ebc0cd7c875323760372d.tar.xz
chishop-fe01b7f71fe925965c0ebc0cd7c875323760372d.zip
Authenticate using HTTP Basic Auth
-rw-r--r--djangopypi/views.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/djangopypi/views.py b/djangopypi/views.py
index 560b461..296ecea 100644
--- a/djangopypi/views.py
+++ b/djangopypi/views.py
@@ -72,8 +72,24 @@ def parse_weird_post_data(data):
72 return MultiValueDict(post_data), files 72 return MultiValueDict(post_data), files
73 73
74 74
75def login_basic_auth(request):
76 authentication = request.META.get("HTTP_AUTHORIZATION")
77 if not auth:
78 return
79 (authmeth, auth) = authentication.split(' ', 1)
80 if authmeth.lower() != "basic":
81 return
82 auth = auth.strip().decode("base64")
83 username, password = auth.split(":", 1)
84 return authenticate(username=username, password=password)
85
86
75def simple(request, template_name="djangopypi/simple.html"): 87def simple(request, template_name="djangopypi/simple.html"):
76 if request.method == "POST": 88 if request.method == "POST":
89 user = login_basic_auth(request)
90 if not user:
91 return HttpResponseForbidden("Must give credentials.")
92 login(request, user)
77 if not request.user.is_authenticated(): 93 if not request.user.is_authenticated():
78 return HttpResponseForbidden( 94 return HttpResponseForbidden(
79 "Not logged in, or invalid user/password") 95 "Not logged in, or invalid user/password")