Compare commits
1 Commits
main
...
temp-login
| Author | SHA1 | Date | |
|---|---|---|---|
| d09a875488 |
@@ -10,6 +10,8 @@ The MQTT Client is a FastAPI App and can be launched natively or with FastAPI pr
|
|||||||
|
|
||||||
The script ``sql_startup.sql`` contains commands to set up the layout of the database which the program expects.
|
The script ``sql_startup.sql`` contains commands to set up the layout of the database which the program expects.
|
||||||
|
|
||||||
|
TODO: probably delete the "extra commands" and segment the example data out
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
|
|
||||||
This repository does not include two external dependencies, namely the SQL server and MQTT broker. The tested choices for those dependencies are MariaDB and Mosquitto, but alternatives may work as well
|
This repository does not include two external dependencies, namely the SQL server and MQTT broker. The tested choices for those dependencies are MariaDB and Mosquitto, but alternatives may work as well
|
||||||
|
|||||||
@@ -91,11 +91,19 @@ class DatabaseConnect:
|
|||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return res[0] == 1
|
return res[0] == 1
|
||||||
|
|
||||||
|
def get_all_perms(self) -> list[tuple[str, str, bool, bool, bool]]:
|
||||||
|
self.cursor.execute("SELECT users.`username`, rooms.`shortname`, permissions.`view`, permissions.`control`, permissions.`administer` FROM permissions LEFT JOIN users ON permissions.`userID` = users.`ID` LEFT JOIN rooms ON permissions.`roomID` = rooms.`ID`;")
|
||||||
|
return [x for x in self.cursor.fetchall()]
|
||||||
|
|
||||||
# def roomID_from_shortname(self, shortname):
|
# def roomID_from_shortname(self, shortname):
|
||||||
# self.cursor.execute("SELECT rooms.`ID` from rooms WHERE rooms.shortname = ?;",(shortname,))
|
# self.cursor.execute("SELECT rooms.`ID` from rooms WHERE rooms.shortname = ?;",(shortname,))
|
||||||
# return self.cursor.fetchone()
|
# return self.cursor.fetchone()
|
||||||
|
|
||||||
|
def get_devices_in_room_shortname(self, shortname) -> list[tuple[int, str]]:
|
||||||
|
self.cursor.execute("Select devices.`ID`, devices.`name` FROM devices LEFT JOIN rooms ON devices.`roomID` = rooms.`ID` WHERE rooms.shortname = ?;",(shortname,))
|
||||||
|
return [x for x in self.cursor.fetchall()]
|
||||||
|
|
||||||
def get_sensors_in_room_shortname(self, shortname) -> list[tuple[int, int]]:
|
def get_sensors_in_room_shortname(self, shortname) -> list[tuple[int, int]]:
|
||||||
self.cursor.execute("Select sensors.`ID`, sensors.`Type` FROM sensors LEFT JOIN devices ON devices.`ID` = sensors.`deviceID` LEFT JOIN rooms ON devices.`roomID` = rooms.`ID` WHERE rooms.shortname = ?;",(shortname,))
|
self.cursor.execute("Select sensors.`ID`, sensors.`Type` FROM sensors LEFT JOIN devices ON devices.`ID` = sensors.`deviceID` LEFT JOIN rooms ON devices.`roomID` = rooms.`ID` WHERE rooms.shortname = ?;",(shortname,))
|
||||||
return [x for x in self.cursor.fetchall()]
|
return [x for x in self.cursor.fetchall()]
|
||||||
|
|||||||
@@ -52,3 +52,7 @@ SELECT permissions.`view` FROM permissions LEFT JOIN rooms ON permissions.`roomI
|
|||||||
|
|
||||||
# get latest reading from a sensor
|
# get latest reading from a sensor
|
||||||
SELECT readings.`Timestamp`, readings.`reading` FROM readings WHERE readings.`sensorID` = '1' ORDER BY readings.`Timestamp` DESC FETCH FIRST 1 ROWS ONLY;
|
SELECT readings.`Timestamp`, readings.`reading` FROM readings WHERE readings.`sensorID` = '1' ORDER BY readings.`Timestamp` DESC FETCH FIRST 1 ROWS ONLY;
|
||||||
|
|
||||||
|
Select sensors.`ID`, sensors.`Type` FROM sensors LEFT JOIN devices ON devices.`ID` = sensors.`deviceID` LEFT JOIN rooms ON devices.`roomID` = rooms.`ID` WHERE rooms.shortname = "101";
|
||||||
|
|
||||||
|
SELECT users.`ID`, users.`username`, users.`administer` FROM Users;
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ a:hover {
|
|||||||
padding: 20px;
|
padding: 20px;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
flex-grow: 9;
|
flex-grow: 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
.topline {
|
.topline {
|
||||||
|
|||||||
1
web.py
1
web.py
@@ -156,6 +156,7 @@ def room_page(room_name=None):
|
|||||||
).render()
|
).render()
|
||||||
|
|
||||||
@app.route("/users", methods=["GET","POST"])
|
@app.route("/users", methods=["GET","POST"])
|
||||||
|
@login_required
|
||||||
def user_management():
|
def user_management():
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
# no options allowed for logged out users
|
# no options allowed for logged out users
|
||||||
|
|||||||
@@ -27,7 +27,10 @@
|
|||||||
</div>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
<div><a href="/devices">Device Management</a></div>
|
<div><a href="/devices">Device Management</a></div>
|
||||||
<div><a href="/users">User Management</a></div>
|
{% if user %}
|
||||||
|
<div><a href="/users.html">User Management</a></div>
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="right-flex">
|
<div class="right-flex">
|
||||||
|
|||||||
@@ -74,6 +74,57 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<h3>User Permissions:</h3>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr class="table-header">
|
||||||
|
<th>Username</th>
|
||||||
|
<th>Room</th>
|
||||||
|
<th>View</th>
|
||||||
|
<th>Control</th>
|
||||||
|
<th>Administer</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
<tr class="searchbar">
|
||||||
|
<td colspan="255">
|
||||||
|
<input type="text" id="permSearch" placeholder="Search by username..." onkeyup="tableSearch('permSearch', 'permlist',0)">
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="permlist">
|
||||||
|
{% for perm in permlist %}
|
||||||
|
<tr>
|
||||||
|
<form method="POST" action="/users">
|
||||||
|
<td> {{ perm[0] }} </td>
|
||||||
|
<td> {{ perm[1] }} </td>
|
||||||
|
<td>
|
||||||
|
<input type="checkbox" name="change-view"
|
||||||
|
{% if perm[2] %}
|
||||||
|
checked
|
||||||
|
{% else %}
|
||||||
|
{% endif %}
|
||||||
|
>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input type="checkbox" name="change-purge"
|
||||||
|
{% if perm[3] %}
|
||||||
|
checked
|
||||||
|
{% else %}
|
||||||
|
{% endif %}
|
||||||
|
>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input type="checkbox" name="change-administer"
|
||||||
|
{% if perm[2] %}
|
||||||
|
checked
|
||||||
|
{% else %}
|
||||||
|
{% endif %}
|
||||||
|
>
|
||||||
|
</td>
|
||||||
|
</form>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
{% else %}
|
{% else %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user