prepare route protection
This commit is contained in:
@ -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:
|
||||
|
9
owrx/controllers/session.py
Normal file
9
owrx/controllers/session.py
Normal 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")
|
21
owrx/controllers/settings.py
Normal file
21
owrx/controllers/settings.py
Normal 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")
|
Reference in New Issue
Block a user