2020-07-12 18:53:04 +00:00
|
|
|
# Web views
|
2020-04-11 14:20:25 +00:00
|
|
|
from pathlib import Path
|
|
|
|
from flask import Flask, send_from_directory, render_template
|
2020-06-30 20:24:07 +00:00
|
|
|
|
2020-07-12 18:53:04 +00:00
|
|
|
from jellyfin_accounts import config, app, g, css_file, data_store
|
2020-06-16 19:07:47 +00:00
|
|
|
from jellyfin_accounts import web_log as log
|
2020-07-12 18:53:04 +00:00
|
|
|
from jellyfin_accounts.web_api import checkInvite, validator
|
2020-04-11 14:20:25 +00:00
|
|
|
|
|
|
|
|
2020-07-12 18:53:04 +00:00
|
|
|
def bsVersion():
|
|
|
|
if config.getboolean("ui", "bs5"):
|
|
|
|
return 5
|
|
|
|
return 4
|
2020-07-06 19:53:14 +00:00
|
|
|
|
|
|
|
|
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",
|
2020-07-05 14:09:42 +00:00
|
|
|
bs5=config.getboolean("ui", "bs5"),
|
2020-07-04 21:17:49 +00:00
|
|
|
css_file=css_file,
|
2020-06-21 19:29:53 +00:00
|
|
|
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",
|
2020-07-05 14:09:42 +00:00
|
|
|
bs5=config.getboolean("ui", "bs5"),
|
2020-07-04 21:17:49 +00:00
|
|
|
css_file=css_file,
|
2020-06-21 19:29:53 +00:00
|
|
|
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-07-05 13:38:07 +00:00
|
|
|
if "admin.js" in path:
|
2020-07-05 20:39:58 +00:00
|
|
|
return (
|
2020-07-12 18:53:04 +00:00
|
|
|
render_template("admin.js", bsVersion=bsVersion(), css_file=css_file),
|
2020-07-05 20:39:58 +00:00
|
|
|
200,
|
|
|
|
{"Content-Type": "text/javascript"},
|
|
|
|
)
|
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",
|
2020-07-05 14:09:42 +00:00
|
|
|
bs5=config.getboolean("ui", "bs5"),
|
2020-07-04 21:17:49 +00:00
|
|
|
css_file=css_file,
|
2020-06-21 19:29:53 +00:00
|
|
|
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")
|
2020-04-19 21:35:51 +00:00
|
|
|
try:
|
2020-06-21 19:29:53 +00:00
|
|
|
email = data_store.invites[path]["email"]
|
2020-06-14 16:58:18 +00:00
|
|
|
except KeyError:
|
2020-06-21 19:29:53 +00:00
|
|
|
email = ""
|
|
|
|
return render_template(
|
|
|
|
"form.html",
|
2020-07-05 14:09:42 +00:00
|
|
|
bs5=config.getboolean("ui", "bs5"),
|
2020-07-04 21:17:49 +00:00
|
|
|
css_file=css_file,
|
2020-06-21 19:29:53 +00:00
|
|
|
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"),
|
2020-07-12 18:53:04 +00:00
|
|
|
requirements=validator().getCriteria(),
|
2020-06-21 19:29:53 +00:00
|
|
|
email=email,
|
2020-06-28 23:35:51 +00:00
|
|
|
username=(not config.getboolean("email", "no_username")),
|
2020-06-21 19:29:53 +00:00
|
|
|
)
|
|
|
|
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",
|
2020-07-05 14:09:42 +00:00
|
|
|
bs5=config.getboolean("ui", "bs5"),
|
2020-07-04 21:17:49 +00:00
|
|
|
css_file=css_file,
|
2020-06-21 19:29:53 +00:00
|
|
|
contactMessage=config["ui"]["contact_message"],
|
|
|
|
)
|