Compare commits
4 Commits
fc5dc23c0e
...
c1e20e5524
| Author | SHA1 | Date | |
|---|---|---|---|
|
c1e20e5524
|
|||
|
d56256f681
|
|||
|
bbaffb344f
|
|||
|
50be48dba4
|
@@ -0,0 +1,5 @@
|
|||||||
|
from .auth import auth_bp
|
||||||
|
from .index import index_bp
|
||||||
|
from .panel import panel_bp
|
||||||
|
|
||||||
|
__all__ = ["auth_bp", "index_bp", "panel_bp"]
|
||||||
|
|||||||
42
src/judas_server/web/routes/auth.py
Normal file
42
src/judas_server/web/routes/auth.py
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import annotations
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
import flask
|
||||||
|
import flask_login
|
||||||
|
|
||||||
|
from judas_server.web.user import User
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from werkzeug.wrappers import Response
|
||||||
|
|
||||||
|
auth_bp: flask.Blueprint = flask.Blueprint(
|
||||||
|
"auth", __name__, url_prefix="/auth"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@auth_bp.route("/login", methods=["GET", "POST"])
|
||||||
|
def login() -> Response | str:
|
||||||
|
"""Handles user login via password form."""
|
||||||
|
if flask.request.method == "POST":
|
||||||
|
password = flask.request.form.get("password", "")
|
||||||
|
if password == flask.current_app.config["PASSWORD"]:
|
||||||
|
user = User("admin")
|
||||||
|
flask_login.login_user(user)
|
||||||
|
next_page = flask.request.args.get("next")
|
||||||
|
return flask.redirect(next_page or flask.url_for("index.index"))
|
||||||
|
# return flask.redirect(flask.url_for("panel.panel"))
|
||||||
|
else:
|
||||||
|
return flask.render_template(
|
||||||
|
"login.html",
|
||||||
|
error="Invalid password. Please try again.",
|
||||||
|
)
|
||||||
|
return flask.render_template("login.html")
|
||||||
|
|
||||||
|
|
||||||
|
@auth_bp.route("/logout")
|
||||||
|
@flask_login.login_required
|
||||||
|
def logout() -> Response:
|
||||||
|
"""Logs out the current user."""
|
||||||
|
flask_login.logout_user()
|
||||||
|
return flask.redirect(flask.url_for("index.index"))
|
||||||
20
src/judas_server/web/routes/index.py
Normal file
20
src/judas_server/web/routes/index.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import annotations
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
import flask
|
||||||
|
import flask_login
|
||||||
|
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from werkzeug.wrappers import Response
|
||||||
|
|
||||||
|
index_bp: flask.Blueprint = flask.Blueprint("index", __name__)
|
||||||
|
|
||||||
|
|
||||||
|
@index_bp.route("/")
|
||||||
|
def index() -> Response | str:
|
||||||
|
"""Renders the index page."""
|
||||||
|
return flask.render_template(
|
||||||
|
"index.html", logged=flask_login.current_user.is_authenticated
|
||||||
|
)
|
||||||
27
src/judas_server/web/routes/panel.py
Normal file
27
src/judas_server/web/routes/panel.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import annotations
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
import flask
|
||||||
|
import flask_login
|
||||||
|
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from werkzeug.wrappers import Response
|
||||||
|
|
||||||
|
panel_bp: flask.Blueprint = flask.Blueprint(
|
||||||
|
"panel", __name__, url_prefix="/panel"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@panel_bp.route("/")
|
||||||
|
@flask_login.login_required
|
||||||
|
def panel() -> str:
|
||||||
|
"""Renders the main panel page with PC details.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Rendered HTML template with PC details.
|
||||||
|
"""
|
||||||
|
return flask.render_template(
|
||||||
|
"panel.html", username=flask_login.current_user.id, pcs={}
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user