Add HTTP auth password prompt

This commit is contained in:
Kload 2013-06-30 11:57:23 +00:00
parent 88dfbfc97f
commit b0dd6a2b2a

View file

@ -36,12 +36,14 @@ def http_exec(request):
# Simple HTTP auth # Simple HTTP auth
else: else:
authorized = request.getUser() == 'admin' authorized = request.getUser() == 'admin'
try: YunoHostLDAP(password=request.getPassword()) if authorized:
except YunoHostError: authorized = False try: YunoHostLDAP(password=request.getPassword())
except YunoHostError: authorized = False
if not authorized: if not authorized:
request.setResponseCode(401, 'Unauthorized') request.setResponseCode(401, 'Unauthorized')
request.setHeader('Access-Control-Allow-Origin', '*') request.setHeader('Access-Control-Allow-Origin', '*')
request.setHeader('www-authenticate', 'Basic realm="Restricted Area"')
return 'Unauthorized' return 'Unauthorized'
# Sanitize arguments # Sanitize arguments