From 6f991c0124bad1e089095aa2b5d1ad43100ea8b0 Mon Sep 17 00:00:00 2001 From: Artem Synytsyn Date: Sat, 13 Jan 2024 21:51:31 +0200 Subject: [PATCH 1/4] Fix add user functionality --- app/api/web_api.py | 3 +- app/templates/prismo/users.html | 73 ++++++++++++++++++++------------- 2 files changed, 46 insertions(+), 30 deletions(-) diff --git a/app/api/web_api.py b/app/api/web_api.py index 58e25ac..68c6b61 100644 --- a/app/api/web_api.py +++ b/app/api/web_api.py @@ -85,8 +85,7 @@ def api_get_user_permissions(): @web_api.route("/api/users", methods=["POST"]) def api_add_user(): user_data = request.get_json() - - user = User(user_data["name"], user_data["key"], user_data.get("slack_id")) + user = User(user_data["name"], user_data["key"]) number_of_new_user_added = user.save() diff --git a/app/templates/prismo/users.html b/app/templates/prismo/users.html index c8ebea4..c3ffca2 100644 --- a/app/templates/prismo/users.html +++ b/app/templates/prismo/users.html @@ -20,41 +20,60 @@
Add last used RFID card as new user: { + console.error('Error fetching latest key:', error); + // Handle the error appropriately, e.g., display an error message + }); + }); async function getLatestKey() { try { - const response = await fetch('/api/devices/latest_key') - const data = await response.json() - return data + const response = await fetch('/api/devices/latest_key'); + const data = await response.json(); + console.log("Latest key data:", data); // Log for debugging + return data; } catch (error) { - console.error('Error:', error) + console.error('Error fetching latest key:', error); + return null; // Or throw an error } } - + async function addUser(name) { - const key = latestKey.user_key try { - const response = await fetch('/api/users', { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ name, key }) - }) - console.log(response) - if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`); + const latestKey = await getLatestKey(); // Wait for API call + + if (latestKey && latestKey.user_key) { + const key = latestKey.user_key; + const response = await fetch('/api/users', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ name, key }) + }); + + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + + const newData = await fetchData(); + usersTable.clear().rows.add(newData).draw(); + } else { + console.error("Latest key data is missing or invalid."); + // Handle the error appropriately, e.g., display a message to the user } - // usersTable.row.add({ - // name, - // key, - // operation: '' - // }).draw() - const newData = await fetchData() - usersTable.clear().rows.add( newData ).draw() } catch (error) { - console.error('Error:', error) + console.error('Error adding user:', error); + // Handle the error appropriately, e.g., display a message to the user } } @@ -137,11 +156,9 @@
Add last used RFID card as new user: Date: Mon, 15 Jan 2024 12:25:56 +0200 Subject: [PATCH 3/4] Fix pylint --- app/utils/fimware_updater.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/utils/fimware_updater.py b/app/utils/fimware_updater.py index b4748bc..d05fb27 100644 --- a/app/utils/fimware_updater.py +++ b/app/utils/fimware_updater.py @@ -36,13 +36,15 @@ def update_firmware_full(socket, device_id): data = {"text": "", "progress": 0, "status": "is_running"} try: script_path = Path(app.config["PRISMO"]["READER_FIRMWARE_FLASHING_SCRIPT_PATH"]) - # Check and set wifi credentials as environment variables. Since flasher script requires them as ENV variables, - # and looks like Raspberry Pi OS do not allows to get wifi password to console, this trick is used here. + # Check and set wifi credentials as environment variables. Since flasher script requires + # them as ENV variables,and looks like Raspberry Pi OS do not allows to get wifi password + # to console, this trick is used here. run_environment = os.environ.copy() run_environment["HOST_WIFI_SSID"] = app.config["PRISMO"]["WIFI_SSID"] run_environment["HOST_WIFI_PASSWORD"] = app.config["PRISMO"]["WIFI_PASSWORD"] script_cwd = script_path.parent - process = subprocess.Popen([script_path, device_id], cwd=script_cwd, stdout=subprocess.PIPE, env=run_environment) + process = subprocess.Popen([script_path, device_id], cwd=script_cwd, + stdout=subprocess.PIPE, env=run_environment) except FileNotFoundError: data["text"] = "Cannot find firmware update script" data["status"] = "Device flashing failed" From fb80bf0c4644b585a09a8cb99431d9f07c6ccb29 Mon Sep 17 00:00:00 2001 From: Artem Synytsyn Date: Sat, 20 Jan 2024 23:21:13 +0200 Subject: [PATCH 4/4] Add image and some fixes --- app/config_default.json | 4 +- app/config_docker.json | 24 +++++++++ app/static/prismo.svg | 91 +++++++++++++++++++++++++++++++++++ app/templates/auth/login.html | 3 +- docs/slack_plugin.md | 6 +++ requirements.txt | 10 ++-- 6 files changed, 131 insertions(+), 7 deletions(-) create mode 100644 app/config_docker.json create mode 100644 app/static/prismo.svg create mode 100644 docs/slack_plugin.md diff --git a/app/config_default.json b/app/config_default.json index e348790..3e6c171 100644 --- a/app/config_default.json +++ b/app/config_default.json @@ -23,6 +23,8 @@ "SLACK_TOKEN": "xoxb-this-is-not-areal-slack-token" } }, - "READER_FIRMWARE_FLASHING_SCRIPT_PATH": "/home/artsin/Dev/prismo-reader/src/flasher.sh" + "READER_FIRMWARE_FLASHING_SCRIPT_PATH": "/home/artsin/Dev/prismo-reader/src/flasher.sh", + "WIFI_SSID": "yourSSID", + "WIFI_PASSWORD": "yourWifiPassword" } } \ No newline at end of file diff --git a/app/config_docker.json b/app/config_docker.json new file mode 100644 index 0000000..2953d84 --- /dev/null +++ b/app/config_docker.json @@ -0,0 +1,24 @@ +{ + "DEBUG": true, + "TESTING": true, + "SECRET_KEY": "secret_key", + "USE_X_SENDFILE": false, + "APPLICATION_ROOT": "/", + "SESSION_COOKIE_NAME": "session", + "SESSION_COOKIE_HTTPONLY": true, + "SESSION_COOKIE_SECURE": false, + "SESSION_REFRESH_EACH_REQUEST": true, + "TRAP_HTTP_EXCEPTIONS": false, + "EXPLAIN_TEMPLATE_LOADING": false, + "PREFERRED_URL_SCHEME": "http", + "MAX_COOKIE_SIZE": 4093, + "DATABASE_URI": "file:./external/database.db", + "PRISMO": { + "NOTIFIER": { + "CURRENT_NOTIFIER": "SLACK", + "SLACK_CHANNEL": "#prismo-debug", + "SLACK_TOKEN": "xoxb-THIS-ISNOTAREAL-SLACKTOKEN" + }, + "READER_FIRMWARE_FLASHING_SCRIPT_PATH": "/app/external/firmware/src/flasher.sh" + } +} diff --git a/app/static/prismo.svg b/app/static/prismo.svg new file mode 100644 index 0000000..61574a2 --- /dev/null +++ b/app/static/prismo.svg @@ -0,0 +1,91 @@ + + + + + + + + + + + + + diff --git a/app/templates/auth/login.html b/app/templates/auth/login.html index 1cbfc54..88300ce 100644 --- a/app/templates/auth/login.html +++ b/app/templates/auth/login.html @@ -9,7 +9,8 @@