Compare commits
No commits in common. "b1215fbc1b3ec6aa18fe9138e0251de173d94915" and "269c6e511f7f48ab2f6bc50ad6e7b7887c33305a" have entirely different histories.
b1215fbc1b
...
269c6e511f
3 changed files with 3 additions and 41 deletions
|
|
@ -6,7 +6,6 @@ import mimetypes
|
||||||
import os
|
import os
|
||||||
from urllib.request import quote
|
from urllib.request import quote
|
||||||
import zipfile
|
import zipfile
|
||||||
import base64
|
|
||||||
|
|
||||||
import ox
|
import ox
|
||||||
|
|
||||||
|
|
@ -27,42 +26,7 @@ import state
|
||||||
import logging
|
import logging
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
class OMLHandler(tornado.web.RequestHandler):
|
||||||
class OptionalBasicAuthMixin(object):
|
|
||||||
class SendChallenge(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def prepare(self):
|
|
||||||
if settings.preferences.get('authentication'):
|
|
||||||
try:
|
|
||||||
self.authenticate_user()
|
|
||||||
except self.SendChallenge:
|
|
||||||
self.send_auth_challenge()
|
|
||||||
|
|
||||||
def send_auth_challenge(self):
|
|
||||||
realm = "Open Media Library"
|
|
||||||
hdr = 'Basic realm="%s"' % realm
|
|
||||||
self.set_status(401)
|
|
||||||
self.set_header('www-authenticate', hdr)
|
|
||||||
self.finish()
|
|
||||||
return False
|
|
||||||
|
|
||||||
def authenticate_user(self):
|
|
||||||
auth_header = self.request.headers.get('Authorization')
|
|
||||||
if not auth_header or not auth_header.startswith('Basic '):
|
|
||||||
raise self.SendChallenge()
|
|
||||||
|
|
||||||
auth_data = auth_header.split(None, 1)[-1]
|
|
||||||
auth_data = base64.b64decode(auth_data).decode('ascii')
|
|
||||||
username, password = auth_data.split(':', 1)
|
|
||||||
|
|
||||||
auth = settings.preferences.get('authentication')
|
|
||||||
if auth.get('username') == username and auth.get('password') == password:
|
|
||||||
self._current_user = username
|
|
||||||
else:
|
|
||||||
raise self.SendChallenge()
|
|
||||||
|
|
||||||
class OMLHandler(OptionalBasicAuthMixin, tornado.web.RequestHandler):
|
|
||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
pass
|
pass
|
||||||
|
|
@ -176,7 +140,7 @@ class ReaderHandler(OMLHandler):
|
||||||
path = os.path.join(settings.static_path, html)
|
path = os.path.join(settings.static_path, html)
|
||||||
return serve_static(self, path, 'text/html')
|
return serve_static(self, path, 'text/html')
|
||||||
|
|
||||||
class UploadHandler(OMLHandler):
|
class UploadHandler(tornado.web.RequestHandler):
|
||||||
|
|
||||||
def initialize(self, context=None):
|
def initialize(self, context=None):
|
||||||
self._context = context
|
self._context = context
|
||||||
|
|
|
||||||
|
|
@ -362,9 +362,8 @@ oml.ui.folders = function() {
|
||||||
oml.$ui.libraryList[index].options({
|
oml.$ui.libraryList[index].options({
|
||||||
items: library
|
items: library
|
||||||
});
|
});
|
||||||
// library + public + lists
|
|
||||||
oml.$ui.folder[index].$content
|
oml.$ui.folder[index].$content
|
||||||
.css({height: 16 + 16 + items.length * 16 + 'px'});
|
.css({height: 16 + items.length * 16 + 'px'});
|
||||||
oml.$ui.folderList[index].options({
|
oml.$ui.folderList[index].options({
|
||||||
items: items
|
items: items
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -601,7 +601,6 @@ oml.ui.mainMenu = function() {
|
||||||
that[data.value ? 'enableItem' : 'disableItem']('book');
|
that[data.value ? 'enableItem' : 'disableItem']('book');
|
||||||
that[data.value ? 'disableItem' : 'enableItem']('showfilters');
|
that[data.value ? 'disableItem' : 'enableItem']('showfilters');
|
||||||
that[data.value ? 'enableItem' : 'disableItem']('showbrowser');
|
that[data.value ? 'enableItem' : 'disableItem']('showbrowser');
|
||||||
that[data.value ? 'enableItem' : 'disableItem']('showannotations');
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
oml_itemview: function(data) {
|
oml_itemview: function(data) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue