prepare route protection

This commit is contained in:
Jakob Ketterl
2020-02-23 19:23:18 +01:00
parent aa9737498a
commit 0a20cb5e41
4 changed files with 40 additions and 0 deletions

View File

@ -21,6 +21,11 @@ class Controller(ABC):
content = content.encode()
self.handler.wfile.write(content)
def send_redirect(self, location, code=303):
self.handler.send_response(code)
self.handler.send_header("Location", location)
self.handler.end_headers()
def handle_request(self):
action = "indexAction"
if "action" in self.options:

View File

@ -0,0 +1,9 @@
from . import Controller
class SessionController(Controller):
def loginAction(self):
self.send_response("login happening here")
def logoutAction(self):
self.send_redirect("logout happening here")

View File

@ -0,0 +1,21 @@
from . import Controller
class Authentication(object):
def isAuthenticated(self, request):
return False
class SettingsController(Controller):
def __init__(self, handler, request, options):
self.authentication = Authentication()
super().__init__(handler, request, options)
def handle_request(self):
if self.authentication.isAuthenticated(self.request):
super().handle_request()
else:
self.send_redirect("/login")
def indexAction(self):
self.send_response("actual content here")