43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
# -*- 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 credentials.",
|
|
)
|
|
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"))
|