prepare route protection
This commit is contained in:
parent
aa9737498a
commit
0a20cb5e41
@ -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")
|
@ -11,6 +11,8 @@ from owrx.controllers.assets import (
|
||||
from owrx.controllers.websocket import WebSocketController
|
||||
from owrx.controllers.api import ApiController
|
||||
from owrx.controllers.metrics import MetricsController
|
||||
from owrx.controllers.settings import SettingsController
|
||||
from owrx.controllers.session import SessionController
|
||||
from http.server import BaseHTTPRequestHandler
|
||||
from urllib.parse import urlparse, parse_qs
|
||||
import re
|
||||
@ -91,6 +93,9 @@ class Router(object):
|
||||
StaticRoute("/features", FeatureController),
|
||||
StaticRoute("/api/features", ApiController),
|
||||
StaticRoute("/metrics", MetricsController),
|
||||
StaticRoute("/settings", SettingsController),
|
||||
StaticRoute("/login", SessionController, {"action": "loginAction"}),
|
||||
StaticRoute("/logout", SessionController, {"action": "logoutAction"}),
|
||||
]
|
||||
|
||||
def find_route(self, request):
|
||||
|
Loading…
Reference in New Issue
Block a user