diff --git a/app.py b/app.py index ecfdf61..94e3fc1 100644 --- a/app.py +++ b/app.py @@ -142,6 +142,64 @@ def login(): return redirect(url_for(session.get("main", "index_ade"))) +@app.route("/register", methods=["GET", "POST"]) +def register(): + if request.method == "POST": + act = request.form.get("action") + match act: + case "create": + username = request.form["username"] + password = request.form["password"] + udata = db.users.find_one({"id": username}) + if udata or not username or not password: + abort(400) + salt = urandom(32) + hash = scrypt(password.encode("utf-8"), salt=salt, **SCRYPT_PARAMS) + db.users.insert_one( + { + "id": username, + "hash": hash, + "salt": salt, + "perm": [], + "quad": ["ade"], + } + ) + case "edit": + for entry in request.form: + if entry.count("/") == 2: + ptype, pid, uid = entry.split("/") + value = request.form[entry] + if ptype == "perm": + cur_perms = db.users.find_one( + {"_id": ObjectId(uid)}, {"perm": 1} + ).get("perm", []) + if value == "True": + if pid not in cur_perms: + cur_perms.append(pid) + else: + if pid in cur_perms: + cur_perms.remove(pid) + db.users.update_one( + {"_id": ObjectId(uid)}, {"$set": {"perm": cur_perms}} + ) + if ptype == "quad": + cur_quads = db.users.find_one( + {"_id": ObjectId(uid)}, {"quad": 1} + ).get("quad", []) + if value == "True": + if pid not in cur_quads: + cur_quads.append(pid) + else: + if pid in cur_quads: + cur_quads.remove(pid) + db.users.update_one( + {"_id": ObjectId(uid)}, {"$set": {"quad": cur_quads}} + ) + udatas = list(db.users.find()) + ddatas = sorted(db.domains.find({"public": False}), key=lambda ddata: ddata["id"]) + return render_template("register.html", udatas=udatas, ddatas=ddatas) + + @app.route("/search") def search(): stype = request.args.get("search-type") @@ -347,6 +405,8 @@ def lighting(): result[-1] = {"name": "Ungrouped", "lights": {}} for light in raw["lights"]: ldata = raw["lights"][light] + if not ldata["state"]["reachable"]: + continue if not ldata["state"]["on"]: color = "#000000" elif ldata["state"].get("colormode") == "hs": @@ -361,6 +421,6 @@ def lighting(): ungrouped = False if ungrouped: result[-1]["lights"][light] = ldata - return render_template("lighting.html", ldata=result) + return render_template("lighting.html", ldatas=result) except requests.exceptions.ConnectionError: abort(500) diff --git a/static/register.css b/static/register.css new file mode 100644 index 0000000..646e687 --- /dev/null +++ b/static/register.css @@ -0,0 +1,65 @@ +th { + writing-mode: sideways-lr; +} + +th#save-box { + writing-mode: inherit; + + >button { + display: none; + } +} + +.pgrid[data-mark=True] { + background-color: black; +} + +.pgrid[data-changed] { + border: 3px solid red; +} + +tr { + background-color: var(--color-bg2); +} + +.qheader { + background-color: var(--color-bg1); + vertical-align: top; +} + +#users { + background-color: inherit; +} + +#qh-ade, +.quad-ade { + --hue: var(--ade); +} + +#qh-bea, +.quad-bea { + --hue: var(--bea); +} + +#qh-cam, +.quad-cam { + --hue: var(--cam); +} + +#qh-des, +.quad-des { + --hue: var(--des); +} + +#useradd { + display: flex; + flex-direction: row; + flex-wrap: wrap; + gap: 1em; + align-items: end; + justify-content: center; + + >div>label { + display: block; + } +} \ No newline at end of file diff --git a/static/register.js b/static/register.js new file mode 100644 index 0000000..03dca84 --- /dev/null +++ b/static/register.js @@ -0,0 +1,16 @@ +function getFirst(item, className) { + return item.getElementsByClassName(className)[0] +} + +var saveBtn = document.getElementById("save-btn"); + +for (chk of document.getElementsByClassName("pgrid")) { + chk.onclick = (event) => { + console.log(event.target) + event.target.dataset.mark = event.target.dataset.mark == "True" ? "False" : "True" + event.target.children[0].name = event.target.dataset.targ; + event.target.children[0].value = event.target.dataset.mark; + event.target.dataset.changed = true; + saveBtn.style.display = "block"; + } +} \ No newline at end of file diff --git a/templates/lighting.html b/templates/lighting.html index 6364e0e..3c35947 100644 --- a/templates/lighting.html +++ b/templates/lighting.html @@ -8,14 +8,14 @@ {% block content %}
- {% for group in ldata %} - {% if ldata[group]["lights"] %} + {% for group in ldatas %} + {% if ldatas[group]["lights"] %}
-

{{ ldata[group]["name"] }}

+

{{ ldatas[group]["name"] }}

- {% for light in ldata[group]["lights"] %} + {% for light in ldatas[group]["lights"] %}
- {% set ldata = ldata[group]["lights"][light] %} + {% set ldata = ldatas[group]["lights"][light] %}

{{ ldata["name"] }}

diff --git a/templates/register.html b/templates/register.html new file mode 100644 index 0000000..7993c97 --- /dev/null +++ b/templates/register.html @@ -0,0 +1,61 @@ +{% extends "base.html" %} + +{% block head %} + + +{% endblock %} + +{% block content %} +
+ + + + + {% for udata in udatas %} + + {% endfor %} + + {% set quads = ["ade", "bea", "cam", "des"] %} + {% for quad in quads %} + + + {% for udata in udatas %} + + {% endfor %} + + {% for ddata in ddatas %} + {% if ddata["quad"] == quad %} + + + {% for udata in udatas %} + + {% endfor %} + + {% endif %} + {% endfor %} + {% endfor %} +
+ {{ udata["id"] }}
+

{{ quad }}

+
+ +
{{ ddata["name"] }} ({{ ddata["id"] }}) + +
+ +
+
+
+ + +
+
+ + +
+ +
+
+{% endblock %} \ No newline at end of file