jellyfin-accounts/jellyfin_accounts/web.py

84 lines
2.6 KiB
Python
Raw Normal View History

import json
2020-04-11 14:20:25 +00:00
from pathlib import Path
from flask import Flask, send_from_directory, render_template
from jellyfin_accounts import config, app, g, css, data_store
from jellyfin_accounts import web_log as log
from jellyfin_accounts.web_api import checkInvite, validator
2020-04-11 14:20:25 +00:00
@app.errorhandler(404)
def page_not_found(e):
2020-06-21 19:29:53 +00:00
return (
render_template(
"404.html",
css_href=css["href"],
css_integrity=css["integrity"],
css_crossorigin=css["crossorigin"],
contactMessage=config["ui"]["contact_message"],
),
404,
)
2020-04-11 14:20:25 +00:00
2020-06-21 19:29:53 +00:00
@app.route("/", methods=["GET", "POST"])
2020-04-11 14:20:25 +00:00
def admin():
# return app.send_static_file('admin.html')
2020-06-21 19:29:53 +00:00
return render_template(
"admin.html",
css_href=css["href"],
css_integrity=css["integrity"],
css_crossorigin=css["crossorigin"],
contactMessage="",
email_enabled=config.getboolean("invite_emails", "enabled"),
)
2020-04-11 14:20:25 +00:00
2020-06-21 19:29:53 +00:00
@app.route("/<path:path>")
2020-04-11 14:20:25 +00:00
def static_proxy(path):
2020-06-21 19:29:53 +00:00
if "html" not in path:
2020-04-11 14:20:25 +00:00
return app.send_static_file(path)
2020-06-21 19:29:53 +00:00
return (
render_template(
"404.html",
css_href=css["href"],
css_integrity=css["integrity"],
css_crossorigin=css["crossorigin"],
contactMessage=config["ui"]["contact_message"],
),
404,
)
2020-04-11 14:20:25 +00:00
2020-06-21 19:29:53 +00:00
@app.route("/invite/<path:path>")
2020-04-11 14:20:25 +00:00
def inviteProxy(path):
if checkInvite(path):
2020-06-21 19:29:53 +00:00
log.info(f"Invite {path} used to request form")
try:
2020-06-21 19:29:53 +00:00
email = data_store.invites[path]["email"]
except KeyError:
2020-06-21 19:29:53 +00:00
email = ""
return render_template(
"form.html",
css_href=css["href"],
css_integrity=css["integrity"],
css_crossorigin=css["crossorigin"],
contactMessage=config["ui"]["contact_message"],
helpMessage=config["ui"]["help_message"],
successMessage=config["ui"]["success_message"],
jfLink=config["jellyfin"]["public_server"],
validate=config.getboolean("password_validation", "enabled"),
requirements=validator.getCriteria(),
email=email,
)
elif "admin.html" not in path and "admin.html" not in path:
2020-04-11 14:20:25 +00:00
return app.send_static_file(path)
else:
2020-06-21 19:29:53 +00:00
log.debug("Attempted use of invalid invite")
return render_template(
"invalidCode.html",
css_href=css["href"],
css_integrity=css["integrity"],
css_crossorigin=css["crossorigin"],
contactMessage=config["ui"]["contact_message"],
)