1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Implemented proper authentication for backend

This commit is contained in:
Krateng 2020-07-29 15:52:01 +02:00
parent 5f8e73e6c7
commit 56cc06d905
4 changed files with 21 additions and 1 deletions

View File

@ -15,7 +15,7 @@ links = {
requires = [ requires = [
"bottle>=0.12.16", "bottle>=0.12.16",
"waitress>=1.3", "waitress>=1.3",
"doreah>=1.6.7", "doreah>=1.6.8",
"nimrodel>=0.6.3", "nimrodel>=0.6.3",
"setproctitle>=1.1.10", "setproctitle>=1.1.10",
"wand>=0.5.4", "wand>=0.5.4",

View File

View File

@ -49,6 +49,12 @@ config(
}, },
regular={ regular={
"autostart": False "autostart": False
},
auth={
"multiuser":False,
"cookieprefix":"maloja",
"stylesheets":["/style.css"],
"dbfile":datadir("auth/auth.ddb")
} }
) )

View File

@ -25,6 +25,7 @@ from doreah import settings
from doreah.logging import log from doreah.logging import log
from doreah.timing import Clock from doreah.timing import Clock
from doreah.pyhp import file as pyhpfile from doreah.pyhp import file as pyhpfile
from doreah.auth import get_login_page, authapi, authenticated
# technical # technical
#from importlib.machinery import SourceFileLoader #from importlib.machinery import SourceFileLoader
import importlib import importlib
@ -55,6 +56,7 @@ STATICFOLDER = pkg_resources.resource_filename(__name__,"static")
DATAFOLDER = DATA_DIR DATAFOLDER = DATA_DIR
webserver = Bottle() webserver = Bottle()
authapi.mount(server=webserver)
pthjoin = os.path.join pthjoin = os.path.join
@ -158,6 +160,10 @@ def get_css():
return css return css
@webserver.route("/login")
def login():
return get_login_page()
@webserver.route("/<name>.<ext>") @webserver.route("/<name>.<ext>")
def static(name,ext): def static(name,ext):
assert ext in ["txt","ico","jpeg","jpg","png","less","js"] assert ext in ["txt","ico","jpeg","jpg","png","less","js"]
@ -216,7 +222,15 @@ jinjaenv = Environment(
jinjaenv.globals.update(JINJA_CONTEXT) jinjaenv.globals.update(JINJA_CONTEXT)
@webserver.route("/<name:re:(issues|manual|setup|admin)>")
@authenticated
def static_html_private(name):
return static_html(name)
@webserver.route("/<name>") @webserver.route("/<name>")
def static_html_public(name):
return static_html(name)
def static_html(name): def static_html(name):
linkheaders = ["</style.css>; rel=preload; as=style"] linkheaders = ["</style.css>; rel=preload; as=style"]
keys = remove_identical(FormsDict.decode(request.query)) keys = remove_identical(FormsDict.decode(request.query))