openwebrx/owrx/controllers/session.py

29 lines
1,006 B
Python
Raw Normal View History

2020-02-23 20:13:11 +01:00
from .template import WebpageController
2020-02-23 20:52:32 +01:00
from urllib.parse import parse_qs
import logging
logger = logging.getLogger(__name__)
2020-02-23 19:23:18 +01:00
2020-02-23 20:13:11 +01:00
class SessionController(WebpageController):
2020-02-23 19:23:18 +01:00
def loginAction(self):
2020-02-23 20:13:11 +01:00
self.serve_template("login.html", **self.template_variables())
2020-02-23 19:23:18 +01:00
2020-02-23 20:25:36 +01:00
def processLoginAction(self):
2020-02-23 20:52:32 +01:00
data = parse_qs(self.get_body().decode("utf-8"))
data = {k: v[0] for k, v in data.items()}
logger.debug(data)
if "user" in data and "password" in data:
# TODO actually check user and password
if data["user"] == "admin" and data["password"] == "password":
# TODO pass the final destination
# TODO actual session cookie
self.send_redirect("/settings", cookies=["session-cookie"])
else:
self.send_redirect("/login")
else:
self.send_response("invalid request", code=400)
2020-02-23 20:25:36 +01:00
2020-02-23 19:23:18 +01:00
def logoutAction(self):
self.send_redirect("logout happening here")