From 020a3ccea1522aa456705b9e37b135396f293495 Mon Sep 17 00:00:00 2001 From: W13R <9070224-W13R@users.noreply.gitlab.com> Date: Sat, 28 May 2022 19:38:40 +0200 Subject: [PATCH 01/93] Removed old tests directory --- tests/lib/__init__.py | 18 ------- tests/test-database-stability.py | 84 -------------------------------- 2 files changed, 102 deletions(-) delete mode 100644 tests/lib/__init__.py delete mode 100644 tests/test-database-stability.py diff --git a/tests/lib/__init__.py b/tests/lib/__init__.py deleted file mode 100644 index 3da5d92..0000000 --- a/tests/lib/__init__.py +++ /dev/null @@ -1,18 +0,0 @@ - -def parse_config_from_file(filepath): - - config = {} - - with open(filepath, "r") as f: - lines = f.readlines() - for line in lines: - line = line.lstrip(" ").replace("\n", "") - if line.startswith("export "): - line = line.replace("export ", "").lstrip(" ") - varname = line[:line.find("=")] - varvalue = line[line.find("=")+1:] - if varvalue.startswith("'"): varvalue = varvalue.strip("'") - elif varvalue.startswith('"'): varvalue = varvalue.strip('"') - config[varname] = varvalue - - return config diff --git a/tests/test-database-stability.py b/tests/test-database-stability.py deleted file mode 100644 index 228bb97..0000000 --- a/tests/test-database-stability.py +++ /dev/null @@ -1,84 +0,0 @@ -#!/usr/bin/env python3 - -import os, sys - -from pathlib import Path - -from psycopg2 import connect -from psycopg2 import Error - -from lib import parse_config_from_file - - -USER_ID = 2 -N_NEW_ORDER_ROWS = 1000000 -COMMIT_AFTER = 50 -AMOUNT_PER_ORDER = 1 -PRODUCT_NAME = "Wasser" -DRINK_ID = 1 - - -if __name__ == "__main__": - - - print("\nGetting config...") - - config_file = Path(Path(os.path.dirname(__file__)).parent / "config" / "config.sh").absolute() - - config = parse_config_from_file(config_file) - - print(f"Commit will be done after every {COMMIT_AFTER} rows.") - - x = input(f"Do you want to add {N_NEW_ORDER_ROWS} rows to the app_order table? (enter 'yes' to continue) ") - try: - if str(x) != "yes": - exit() - except ValueError: - exit() - - try: - - print("\nConnecting to database...") - - conn = connect( - user = config["PGDB_USER"], - password = config["PGDB_PASSWORD"], - host = config["PGDB_HOST"], - port = config["PGDB_PORT"], - database = config["PGDB_DB"] - ) - - cur = conn.cursor() - - for i in range(N_NEW_ORDER_ROWS): - - cur.execute(f""" - insert into app_order (datetime, product_name, price_sum, content_litres, drink_id, user_id, amount) - values ( - current_timestamp, - '{PRODUCT_NAME}', - 10.00, - 0.5, - {DRINK_ID}, - {USER_ID}, - {AMOUNT_PER_ORDER} - ) - """) - - if i % COMMIT_AFTER == 0 and not i == 0: - conn.commit() - print(f"\nAdded {i} rows") - - conn.commit() - print(f"\nAdded {N_NEW_ORDER_ROWS} rows") - - print("done with db setup.") - - except (Error, Exception) as err: - - print(f"An error occured while connecting to the database {config['PGDB_DB']} at {config['PGDB_HOST']}:\n{err}", file=sys.stderr) - - finally: - - cur.close() - conn.close() From 672f7d6a80d162be40f296a87b2ccc9a7fe4a52b Mon Sep 17 00:00:00 2001 From: W13R <9070224-W13R@users.noreply.gitlab.com> Date: Sat, 28 May 2022 19:44:36 +0200 Subject: [PATCH 02/93] Update package names for pg_config and Python version in docs --- docs/Setup.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/Setup.md b/docs/Setup.md index f42ba70..caef81a 100644 --- a/docs/Setup.md +++ b/docs/Setup.md @@ -8,10 +8,11 @@ Before the actual setup, you have to satisfy the following dependencies: ### System - `pg_config` - - Fedora/RHEL/Ubuntu: `libpq-dev` + - Ubuntu: `libpq-dev` + - Fedora/RHEL: `libpq-devel` - `Caddy` 2.4.3+ (HTTP Reverse Proxy & Static File Server) - `gcc`, `gettext` -- `Python` 3.9 with pip +- `Python` 3.9+ with pip - `Python` header files - Fedora/RHEL: `python3-devel` - Ubuntu: `python3-dev` From 97462c78841d82c98a6e9daf160702c0118b84c3 Mon Sep 17 00:00:00 2001 From: W13R <9070224-W13R@users.noreply.gitlab.com> Date: Sun, 29 May 2022 15:31:44 +0200 Subject: [PATCH 03/93] Rename example systemd service file --- misc/{drinks-manager.service.sample => drinks-manager.service} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename misc/{drinks-manager.service.sample => drinks-manager.service} (100%) diff --git a/misc/drinks-manager.service.sample b/misc/drinks-manager.service similarity index 100% rename from misc/drinks-manager.service.sample rename to misc/drinks-manager.service From df91a89cd5ec4415ec254ede873f2e387e1f7a83 Mon Sep 17 00:00:00 2001 From: W13R <9070224-W13R@users.noreply.gitlab.com> Date: Sun, 29 May 2022 20:56:16 +0200 Subject: [PATCH 04/93] Updated docs --- README.md | 4 ++-- docs/Configuration.md | 10 +++++----- docs/Setup.md | 28 ++++++++++++++++------------ 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index d84db1e..27df4cf 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Drinks Manager (season 2) -Note: This piece of software is tailored to my own needs. +Note: This software is tailored to my own needs. I probably won't accept feature requests, and don't recommend you to use this software if this isn't exactly what you are looking for. @@ -15,7 +15,7 @@ You have to bring your own PostgreSQL Database though. ## Setup, Installation, Updating and Dependencies -You can find the latest releases [here](https://gitlab.com/W13R/drinks-manager/-/releases), but for Installation/Updating, you should consider using Git. +You can find the latest releases [here](https://gitlab.com/W13R/drinks-manager/-/releases), but you should consider using Git to easily switch between versions. For more information see [Setup](docs/Setup.md). diff --git a/docs/Configuration.md b/docs/Configuration.md index 239dde3..00d5933 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -1,14 +1,14 @@ # Configuration -## Main Configuration +## Main Configuration -`./config/config.sh` +`config/config.sh` -There is no default configuration available, only a sample configuration with explanations. +There is a sample configuration with explanations: [/config/config.sample.sh](/config/config.sample.sh) -## Caddy Server Configuration +## Caddy (Reverse Proxy & Static File Server) -`./config/Caddyfile` +[config/Caddyfile](/config/Caddyfile) The default configuration should work out of the box, don't edit this file unless you know what you're doing. diff --git a/docs/Setup.md b/docs/Setup.md index caef81a..28805cb 100644 --- a/docs/Setup.md +++ b/docs/Setup.md @@ -20,7 +20,7 @@ Before the actual setup, you have to satisfy the following dependencies: ### Python Packages (pip) -All required python packages are listed `in pip-dependencies.txt` +All required python packages are listed in [pip-dependencies.txt](/pip-dependencies.txt) You can install the required python packages with ```bash @@ -32,9 +32,9 @@ You can install the required python packages with You can get the latest version with git: ``` -git clone --branch release-x.x https://gitlab.com/W13R/drinks-manager.git +git clone --branch release-x https://gitlab.com/W13R/drinks-manager.git ``` -(replace x.x with the latest version) +(replace x with the latest version) Alternatively, you can download the [latest release](https://gitlab.com/W13R/drinks-manager/-/releases) and extract the files to your prefered destination. @@ -55,9 +55,9 @@ If you installed the application with git, you can run the following in the drin ``` git fetch -git checkout x.x +git checkout x ``` -(replace x.x with the new version) +(replace x with the new version) If you downloaded the application from the releases page, you can download the new release in the same manner, and overwrite the old files with the new ones. @@ -69,16 +69,20 @@ Further upgrading-instructions may be provided in the Release Notes on the Relea ## III. Database -This project is using PostgreSQL. You have to set up a database by yourself. -The database must have the schema `public` (exists on a new database). Make shure that you create a database user with the necessary privileges to write to and read from the database (SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, CREATE, CONNECT): +This project is using PostgreSQL. You have to set up a database: ```sql --- connected to target database -grant SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES on all tables in schema public to ; -grant CREATE, CONNECT on database to ; +create user drinksmanager password ''; +create database drinksmgr owner drinksmanager; ``` -You can configure your database connection in `config/config.sh`. +After creating the user, you have to edit your `pg_hba.conf` (see https://www.postgresql.org/docs/current/auth-pg-hba-conf.html). +Add the following line: +``` +host drinksmgr drinksmanager 127.0.0.1/32 md5 +``` + +Now you can configure your database connection in `config/config.sh`. ## IV. HTTPS & TLS Certificates @@ -89,7 +93,7 @@ Filepaths: - `config/tls/server.pem` for the certificate - `config/tls/server-key.pem` for the key -You can set another filepath for those files in your caddy configuration at `config/Caddyfile`. +You can set another filepath for those files in your caddy configuration at [config/Caddyfile](/config/Caddyfile). ## V. Configuration From 6ca7f70a2e252065c562471c7aadd9b9c53c6477 Mon Sep 17 00:00:00 2001 From: W13R <9070224-W13R@users.noreply.gitlab.com> Date: Sun, 29 May 2022 20:56:50 +0200 Subject: [PATCH 05/93] Updated sample config --- config/config.sample.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/config/config.sample.sh b/config/config.sample.sh index d82100a..51aa8f0 100644 --- a/config/config.sample.sh +++ b/config/config.sample.sh @@ -1,15 +1,15 @@ # environment variables -export HTTP_PORT=80 # required by caddy, will be redirected to https -export HTTPS_PORT=443 # actual port for webinterface +export HTTP_PORT=80 # required by caddy, will be redirected to https +export HTTPS_PORT=443 # actual port for the webinterface export DJANGO_PORT=8001 # caddy's http port (should be blocked by the firewall) export DJANGO_SESSION_COOKIE_AGE=600 # auto-logout, in seconds -export SESSION_CLEAR_INTERVAL=120 # interval for automatic session clearing, in minutes +export SESSION_CLEAR_INTERVAL=120 # interval for automatic session clearing, in minutes -export DJANGO_LANGUAGE_CODE="en" # the default and fallback language. Currently only de and en are supported. -export DJANGO_TIME_ZONE="CET" +export DJANGO_LANGUAGE_CODE="en" # the default and fallback language, currently only de and en are supported. +export DJANGO_TIME_ZONE="CET" # your timezone export CURRENCY_SUFFIX="$" # if you have another currency symbol, you can specify it here @@ -18,10 +18,10 @@ export CURRENCY_SUFFIX="$" # if you have another currency symbol, you can specif export DJANGO_ENABLE_PASSWORD_VALIDATION="true" # database connection (postgresql) -export PGDB_DB="" # The name of the databae +export PGDB_DB="" # The name of the database export PGDB_USER="" # The database user export PGDB_PASSWORD='' # The password for the database user -export PGDB_HOST="" # The hostname of your database (e.g. example.org or 127.0.0.1) +export PGDB_HOST="127.0.0.1" # The hostname of your database export PGDB_PORT=5432 # The port your database is listening on # log files From 5d96558451caf063fd2b3dcde5f6d4251a8746d7 Mon Sep 17 00:00:00 2001 From: W13R <9070224-W13R@users.noreply.gitlab.com> Date: Sun, 29 May 2022 20:57:38 +0200 Subject: [PATCH 06/93] Bump version to 7 --- lib/env.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/env.sh b/lib/env.sh index 5c3bf23..b49cbd4 100644 --- a/lib/env.sh +++ b/lib/env.sh @@ -2,5 +2,5 @@ export DJANGO_SK_ABS_FP="$(pwd)/config/secret_key.txt" export STATIC_FILES="$(pwd)/static/" -export APP_VERSION="6" +export APP_VERSION="7" export PYTHONPATH="$(pwd)/packages/" From 0833677bbd444ed5a6fabea2019cb4bb67ccb1fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller?= <9070224-W13R@users.noreply.gitlab.com> Date: Mon, 13 Jun 2022 18:47:16 +0200 Subject: [PATCH 07/93] #3 Rename pip-dependencies.txt to requirements.txt --- docs/Setup.md | 2 +- install-pip-dependencies.sh | 2 +- pip-dependencies.txt => requirements.txt | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename pip-dependencies.txt => requirements.txt (100%) diff --git a/docs/Setup.md b/docs/Setup.md index 28805cb..bf3d0c4 100644 --- a/docs/Setup.md +++ b/docs/Setup.md @@ -20,7 +20,7 @@ Before the actual setup, you have to satisfy the following dependencies: ### Python Packages (pip) -All required python packages are listed in [pip-dependencies.txt](/pip-dependencies.txt) +All required python packages are listed in [requirements.txt](/requirements.txt) You can install the required python packages with ```bash diff --git a/install-pip-dependencies.sh b/install-pip-dependencies.sh index 8dfc0d2..6c02848 100755 --- a/install-pip-dependencies.sh +++ b/install-pip-dependencies.sh @@ -4,4 +4,4 @@ wd=$(dirname $0) -pip3 install -r "$wd/pip-dependencies.txt" -t "$wd/packages" +pip3 install -r "$wd/requirements.txt" -t "$wd/packages" diff --git a/pip-dependencies.txt b/requirements.txt similarity index 100% rename from pip-dependencies.txt rename to requirements.txt From 96d4652a041846d240a97d3319950806c65d1969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller?= <9070224-W13R@users.noreply.gitlab.com> Date: Mon, 13 Jun 2022 19:13:27 +0200 Subject: [PATCH 08/93] #1 improve text and translations --- application/app/templates/order.html | 2 +- application/locale/de/LC_MESSAGES/django.mo | Bin 3583 -> 3469 bytes application/locale/de/LC_MESSAGES/django.po | 128 ++++++++++---------- 3 files changed, 63 insertions(+), 67 deletions(-) diff --git a/application/app/templates/order.html b/application/app/templates/order.html index b4f2263..2f1d58f 100644 --- a/application/app/templates/order.html +++ b/application/app/templates/order.html @@ -82,7 +82,7 @@ {% else %} diff --git a/application/locale/de/LC_MESSAGES/django.mo b/application/locale/de/LC_MESSAGES/django.mo index c387ac73ed38ea0301252191dcda6d025d0be34d..07c684c8c574ed25adf7f9061611ea3ad5285e44 100644 GIT binary patch delta 1247 zcmXZaPe>F|9Ki9nx~{smX{i~k=}S{I%Ri|>(m%m4L?JS=Q#HDSF3!%Uw}LLTZ; z1aqiEL4lVJ5oL9VG(zwo9m*htg2D=fP8LB?WZ&O5kJ=4H8_V`@H2++H}1i#9HsKH9gFY~%Javt5Kmz-j-af+fL!W6oveF|r8tY5 z@J)`I%q;lAgarKR`v)V8BV?C=QQU}4z6bsJK9s-)Zo@cosY`SXc-0?2MLFOLEWo!& z3bhiNRB8i%R+*3lKQN3zqGn?umSZte1l5f7*p70NGgyl*mf=m53OzzuKZk@=^T?$Z z=_K(IO8jN1zf8PGDdCDg{^tAB_b-+Q2%7gl&~~y^u)ZD}@hDbe8YSL!?7&+n2U)2gQlU2FEUFi4$gfWDM*@!HKAiH$v$&J-0&c}MB&G`UzT}ma(rv~nd&-tFMROd@A7P?OSwhGp18 zrjCzkCz;e%GL1T!ikT^G=vXRlkIp1=qk*a(*NPjq?wfyRS=_4|XlXrOAMQ2mVb>To zJ9O6(?^WLAke}gX{%XO%{Pc)r>X;d~z0=_`Z#=v|;LJP^mjo)iT%C5wG3IDvaM(NFSOKim5_z8ZEGX5YgL>J||BS=vf zsAT-FxEO!OR-CO@mFj>8bV%UGiLY@U?YTsifXlH3yA!u3{W+At2k}!ZAw^A4b>L*u z{tacLmvIi>L8eguG*p;`hyUo130`0`))KWATW|#~K$4)=V-Idd*-3z(<1t){Kci&o z8p`;aNJw=XDe5kjO#ClO{703fGuQEi7nWhVi&lQar>F28xP|u{0SxS z49WukLfJ?Il`OOs<^39zOm`tgRd!HIfC1c(9?FWZATiXRC;?_sQuqj2gL;$nH;_;H zMJrGOZ$LRiS(NX-Nwg>#I*RO3{ebPvug>ux0dJtJ{C3iA;lHe-y%d*WFEXe47Afiw z)dDOdpQs6x9iG5WJcSZ>28Zz`%0^dnu-0QAYUWoV4-)t!%F2F3+4*^tz!y<6atY<1 z&7cInj67cT_?OyMDHY$M zPRCDcGpWXSUR{SA`s!h8tBz7?Eiy;-ph?#TskmhF47Y4b4zFDGaa7lqu6f^3@%g$x zrri2lsV%zT*fpUJ#)@W4hb6Dvsq?1bL}jDD3nE=|4jb)gYg{Mvc+5M#V+&^LKw~Dg z`>WwxP7h}H^y_W?d$I$$o!P#=z5PQ&JDPKjbtA_$UHgnP+M{#X!Ck}IU5v}+cKTj- zFy?+7)1%|l>F?upO%Jzbqw@IGb0yzc)$4_!(Md}Wc}5SE#*Ee3LLrE3n7kkHy}}5+ zLtebGd3zI2<-qqtGZi#1N>#rakJy>jPTn=6#xI&sN4BWPjr7K6=iJ*Xp+~MxTg#}? yVAR;qv3kUK*63bS4vp_e)|Cj+A=l)M?bJo58d-+e51C;Nj$aH&SU$cm_wRRD#nA!) diff --git a/application/locale/de/LC_MESSAGES/django.po b/application/locale/de/LC_MESSAGES/django.po index 0cdfbab..22c05b2 100644 --- a/application/locale/de/LC_MESSAGES/django.po +++ b/application/locale/de/LC_MESSAGES/django.po @@ -8,11 +8,10 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-12-22 11:07+0100\n" +"POT-Creation-Date: 2022-06-13 19:01+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"Language: \n" +"Last-Translator: Julian Müller (W13R)\n" +"Language: DE\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -26,7 +25,7 @@ msgstr "Django Administrator" msgid "Django administration" msgstr "Django Administration" -#: app/templates/baseLayout.html:43 +#: app/templates/baseLayout.html:41 msgid "An error occured. Please log out and log in again." msgstr "Ein Fehler ist aufgetreten. Bitte ab- und wieder anmelden." @@ -34,7 +33,7 @@ msgstr "Ein Fehler ist aufgetreten. Bitte ab- und wieder anmelden." msgid "Drinks - Deposit" msgstr "Getränke - Einzahlen" -#: app/templates/deposit.html:14 app/templates/userPanel.html:23 +#: app/templates/deposit.html:14 app/templates/userPanel.html:19 msgid "Deposit" msgstr "Einzahlen" @@ -42,7 +41,7 @@ msgstr "Einzahlen" msgid "Amount" msgstr "Summe" -#: app/templates/deposit.html:31 app/templates/order.html:71 +#: app/templates/deposit.html:31 app/templates/order.html:72 #: app/templates/registration/login.html:56 msgid "cancel" msgstr "Abbrechen" @@ -55,7 +54,7 @@ msgstr "Bestätigen" msgid "Drinks - History" msgstr "Getränke - Verlauf" -#: app/templates/history.html:14 app/templates/userPanel.html:21 +#: app/templates/history.html:14 app/templates/userPanel.html:25 msgid "History" msgstr "Verlauf" @@ -63,10 +62,10 @@ msgstr "Verlauf" msgid "last 30 actions" msgstr "letzte 30 Vorgänge" -#: app/templates/history.html:33 app/templates/statistics.html:69 -#: app/templates/statistics.html:89 app/templates/statistics.html:109 -#: app/templates/statistics.html:129 app/templates/statistics.html:149 -#: app/templates/statistics.html:169 +#: app/templates/history.html:33 app/templates/statistics.html:41 +#: app/templates/statistics.html:61 app/templates/statistics.html:81 +#: app/templates/statistics.html:101 app/templates/statistics.html:121 +#: app/templates/statistics.html:141 msgid "No history." msgstr "Kein Verlauf verfügbar." @@ -86,49 +85,47 @@ msgstr "verfügbar" msgid "No drinks available." msgstr "Es sind gerade keine Getränke verfügbar." -#: app/templates/order.html:6 +#: app/templates/order.html:7 msgid "Drinks - Order" msgstr "Getränke - Bestellen" -#: app/templates/order.html:15 +#: app/templates/order.html:16 msgid "Order" msgstr "Bestellung" -#: app/templates/order.html:28 +#: app/templates/order.html:29 msgid "Drink" msgstr "Getränk" -#: app/templates/order.html:33 +#: app/templates/order.html:34 msgid "Price per Item" msgstr "Preis pro Getränk" -#: app/templates/order.html:39 +#: app/templates/order.html:40 msgid "Available" msgstr "Verfügbar" -#: app/templates/order.html:45 +#: app/templates/order.html:46 msgid "Count" msgstr "Anzahl" -#: app/templates/order.html:62 +#: app/templates/order.html:63 msgid "Sum" msgstr "Summe" -#: app/templates/order.html:72 +#: app/templates/order.html:73 msgid "order" msgstr "Bestellen" -#: app/templates/order.html:84 -msgid "You can't order this, because you have a negative balance." -msgstr "" -"Sie können momentan keine Bestellungen aufgeben, da Sie einen negativen " -"Saldo haben." +#: app/templates/order.html:85 +msgid "Your balance is too low to order a drink." +msgstr "Dein Saldo ist zu niedrig um Getränke zu bestellen." -#: app/templates/order.html:85 app/templates/order.html:94 +#: app/templates/order.html:86 app/templates/order.html:95 msgid "back" msgstr "zurück" -#: app/templates/order.html:93 +#: app/templates/order.html:94 msgid "This drink is not available." msgstr "Dieses Getränk ist gerade nicht verfügbar." @@ -138,13 +135,12 @@ msgstr "Getränke - Abgemeldet" #: app/templates/registration/logged_out.html:17 msgid "Logged out! You will be redirected shortly." -msgstr "Sie wurden abgemeldet und werden in Kürze weitergeleitet." +msgstr "Du wurdest abgemeldet und wirst in Kürze weitergeleitet." #: app/templates/registration/logged_out.html:19 msgid "Click here if automatic redirection does not work." msgstr "" -"Bitte klicken Sie hier, wenn die automatische Weiterleitung nicht " -"funktionieren sollte." +"Bitte klicke hier, wenn die automatische Weiterleitung nicht funktioniert." #: app/templates/registration/login.html:7 msgid "Drinks - Login" @@ -164,75 +160,75 @@ msgstr "Anmelden" #: app/templates/registration/login.html:65 msgid "Choose your account" -msgstr "Bitte wählen Sie Ihren Account" +msgstr "Wähle deinen Account" #: app/templates/statistics.html:6 msgid "Drinks - Statistics" msgstr "Getränke - Statistiken" -#: app/templates/statistics.html:15 app/templates/userPanel.html:22 +#: app/templates/statistics.html:15 app/templates/userPanel.html:26 msgid "Statistics" msgstr "Statistiken" #: app/templates/statistics.html:26 -msgid "Choose" -msgstr "Auswählen" - -#: app/templates/statistics.html:31 app/templates/statistics.html:54 msgid "Your orders per drink" msgstr "Deine Bestellungen pro Getränk" -#: app/templates/statistics.html:34 app/templates/statistics.html:134 -msgid "Your orders per weekday" -msgstr "Deine Bestellungen pro Wochentag" - -#: app/templates/statistics.html:37 app/templates/statistics.html:94 -msgid "Your orders per month (last 12 months)" -msgstr "Deine Bestellungen pro Monat (letzte 12 Monate)" - -#: app/templates/statistics.html:40 app/templates/statistics.html:74 -msgid "All orders per drink" -msgstr "Alle Bestellungen pro Getränk" - -#: app/templates/statistics.html:43 app/templates/statistics.html:154 -msgid "All orders per weekday" -msgstr "Alle Bestellungen pro Wochentag" - -#: app/templates/statistics.html:46 app/templates/statistics.html:114 -msgid "All orders per month (last 12 months)" -msgstr "Alle Bestellungen pro Monat (letzte 12 Monate)" - -#: app/templates/statistics.html:58 app/templates/statistics.html:78 +#: app/templates/statistics.html:30 app/templates/statistics.html:50 msgid "drink" msgstr "Getränk" -#: app/templates/statistics.html:59 app/templates/statistics.html:79 -#: app/templates/statistics.html:99 app/templates/statistics.html:119 -#: app/templates/statistics.html:139 app/templates/statistics.html:159 +#: app/templates/statistics.html:31 app/templates/statistics.html:51 +#: app/templates/statistics.html:71 app/templates/statistics.html:91 +#: app/templates/statistics.html:111 app/templates/statistics.html:131 msgid "count" msgstr "Anzahl" -#: app/templates/statistics.html:98 app/templates/statistics.html:118 +#: app/templates/statistics.html:46 +msgid "All orders per drink" +msgstr "Alle Bestellungen pro Getränk" + +#: app/templates/statistics.html:66 +msgid "Your orders per month (last 12 months)" +msgstr "Deine Bestellungen pro Monat (letzte 12 Monate)" + +#: app/templates/statistics.html:70 app/templates/statistics.html:90 msgid "month" msgstr "Monat" -#: app/templates/statistics.html:138 app/templates/statistics.html:158 +#: app/templates/statistics.html:86 +msgid "All orders per month (last 12 months)" +msgstr "Alle Bestellungen pro Monat (letzte 12 Monate)" + +#: app/templates/statistics.html:106 +msgid "Your orders per weekday" +msgstr "Deine Bestellungen pro Wochentag" + +#: app/templates/statistics.html:110 app/templates/statistics.html:130 msgid "day" msgstr "Tag" -#: app/templates/userPanel.html:7 app/templates/userPanel.html:9 +#: app/templates/statistics.html:126 +msgid "All orders per weekday" +msgstr "Alle Bestellungen pro Wochentag" + +#: app/templates/userPanel.html:6 app/templates/userPanel.html:8 msgid "User" msgstr "Benutzer" -#: app/templates/userPanel.html:13 app/templates/userPanel.html:15 +#: app/templates/userPanel.html:12 app/templates/userPanel.html:14 msgid "Balance" msgstr "Saldo" -#: app/templates/userPanel.html:27 +#: app/templates/userPanel.html:22 +msgid "Account" +msgstr "Account" + +#: app/templates/userPanel.html:30 msgid "Change Password" msgstr "Passwort ändern" -#: app/templates/userPanel.html:29 +#: app/templates/userPanel.html:31 msgid "Logout" msgstr "Abmelden" From f406757468da7aede2b7bbb61f7bd65fef37ce24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller?= <9070224-W13R@users.noreply.gitlab.com> Date: Mon, 13 Jun 2022 19:22:36 +0200 Subject: [PATCH 09/93] #2 Fix wrong decimal formatting in Drink and Order models --- application/app/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/app/models.py b/application/app/models.py index 95692b0..7ce9370 100644 --- a/application/app/models.py +++ b/application/app/models.py @@ -51,7 +51,7 @@ class Drink(models.Model): self.deleted = True super().save() - def __str__(self): return f"{self.product_name} ({str(self.content_litres).rstrip('0')}l) - {self.price}{settings.CURRENCY_SUFFIX}" + def __str__(self): return f"{self.product_name} ({float(self.content_litres):.2f}l) - {self.price}{settings.CURRENCY_SUFFIX}" class RegisterTransaction(models.Model): @@ -145,7 +145,7 @@ class Order(models.Model): drink.save() super().delete(*args, **kwargs) - def __str__(self): return f"{self.drink.product_name} ({str(self.drink.content_litres).rstrip('0')}l) x {self.amount} - {self.price_sum}{settings.CURRENCY_SUFFIX}" + def __str__(self): return f"{self.drink.product_name} ({float(self.drink.content_litres):.2f}l) x {self.amount} - {self.price_sum}{settings.CURRENCY_SUFFIX}" class Global(models.Model): From bec4fe7bd0d8b3020983012cb482624aea5ab4c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller?= <9070224-W13R@users.noreply.gitlab.com> Date: Thu, 16 Jun 2022 10:00:44 +0200 Subject: [PATCH 10/93] Removed link to gitlab repo from footer --- application/app/templates/footer.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/app/templates/footer.html b/application/app/templates/footer.html index b490bce..fbfe674 100644 --- a/application/app/templates/footer.html +++ b/application/app/templates/footer.html @@ -2,5 +2,5 @@ From 5893d311fe116996db7e6895bd4dc0aa9bf3c030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller?= <9070224-W13R@users.noreply.gitlab.com> Date: Thu, 16 Jun 2022 10:22:37 +0200 Subject: [PATCH 11/93] #4 moved Logout button out of the dropdown menu --- application/app/templates/userPanel.html | 2 +- static/css/main.css | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/application/app/templates/userPanel.html b/application/app/templates/userPanel.html index 4d0bba3..eecaf88 100644 --- a/application/app/templates/userPanel.html +++ b/application/app/templates/userPanel.html @@ -17,6 +17,7 @@ diff --git a/static/css/main.css b/static/css/main.css index d8377b2..b574189 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -361,5 +361,11 @@ h1 { margin-right: 0; margin-left: 0; margin-top: .5rem; + justify-content: center; + flex-wrap: wrap; + } + .userPanel > .horizontalButtonList > .button, + .userPanel > .horizontalButtonList > .dropDownMenu { + margin: 0.25rem; } } \ No newline at end of file From c7866bfefe01a1f2b500ca9aa73d0af2e0cecacb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller?= <9070224-W13R@users.noreply.gitlab.com> Date: Thu, 16 Jun 2022 10:28:45 +0200 Subject: [PATCH 12/93] Fixed a display issue with the login overlay --- static/css/login.css | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/static/css/login.css b/static/css/login.css index 0b18a9f..8a7fb03 100644 --- a/static/css/login.css +++ b/static/css/login.css @@ -60,8 +60,8 @@ main > h1 { width: fit-content; } .passwordOverlay > form > h1 { - margin-top: 3rem; - margin-bottom: 3rem; + margin-top: 2rem; + margin-bottom: 2rem; } form input[type="password"], form input[type="text"] { width: 94%; @@ -110,7 +110,4 @@ form input[type="password"], form input[type="text"] { font-size: 1.16rem; margin: .2rem; } - .passwordOverlay { - margin-top: 2rem; - } } \ No newline at end of file From 05698544d7ea613794beb2647fe88f63086681a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller?= <9070224-W13R@users.noreply.gitlab.com> Date: Thu, 16 Jun 2022 10:39:29 +0200 Subject: [PATCH 13/93] Small UI enhancement for mobile devices --- static/css/main.css | 3 +++ 1 file changed, 3 insertions(+) diff --git a/static/css/main.css b/static/css/main.css index b574189..72a412f 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -349,6 +349,9 @@ h1 { } /* MOBILE OPTIMIZATIONS */ @media only screen and (max-width: 700px) { + main { + margin-top: 1.5rem; + } .globalMessage span { width: 90%; } From 09aa00f335d48501273cbb72672755acbf3e8e74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller?= <9070224-W13R@users.noreply.gitlab.com> Date: Thu, 16 Jun 2022 10:56:10 +0200 Subject: [PATCH 14/93] Bump version to 8 --- lib/env.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/env.sh b/lib/env.sh index b49cbd4..de54986 100644 --- a/lib/env.sh +++ b/lib/env.sh @@ -2,5 +2,5 @@ export DJANGO_SK_ABS_FP="$(pwd)/config/secret_key.txt" export STATIC_FILES="$(pwd)/static/" -export APP_VERSION="7" +export APP_VERSION="8" export PYTHONPATH="$(pwd)/packages/" From 31b2e395b45fe3ca31cff88f86244e281d9cf3f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller?= <9070224-W13R@users.noreply.gitlab.com> Date: Fri, 24 Jun 2022 18:39:27 +0200 Subject: [PATCH 15/93] #5 disabled backdrop-filter: blur for buttons to fix performance issues --- static/css/main.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/css/main.css b/static/css/main.css index 72a412f..fbc5d2a 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -284,7 +284,7 @@ form .button, form button { outline: none; border: 1px solid var(--glass-border-color); border-radius: var(--glass-corner-radius); - backdrop-filter: var(--glass-blur); + /*backdrop-filter: var(--glass-blur); disabled for performance reasons*/ cursor: pointer; user-select: none; } From a194e05743bdc9ee723d18c45cdc279fe681959e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller?= <9070224-W13R@users.noreply.gitlab.com> Date: Fri, 24 Jun 2022 18:40:53 +0200 Subject: [PATCH 16/93] Bump version to 9 --- lib/env.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/env.sh b/lib/env.sh index de54986..9eeb667 100644 --- a/lib/env.sh +++ b/lib/env.sh @@ -2,5 +2,5 @@ export DJANGO_SK_ABS_FP="$(pwd)/config/secret_key.txt" export STATIC_FILES="$(pwd)/static/" -export APP_VERSION="8" +export APP_VERSION="9" export PYTHONPATH="$(pwd)/packages/" From 500213b5ab621fa10c1d9c8f0696adb623919171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller?= <9070224-W13R@users.noreply.gitlab.com> Date: Wed, 29 Jun 2022 19:02:01 +0200 Subject: [PATCH 17/93] Use 'surname, forename' instead of 'forename surname' in userlist on login page --- application/app/templates/registration/login.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/application/app/templates/registration/login.html b/application/app/templates/registration/login.html index c0179b4..14dc819 100644 --- a/application/app/templates/registration/login.html +++ b/application/app/templates/registration/login.html @@ -71,12 +71,12 @@ {% if user_.first_name %} - {{ user_.first_name }} - {% if user_.last_name %} - {{ user_.last_name }} + {{ user_.last_name }}, {% endif %} + {{ user_.first_name }} + {% else %} {{ user_.username }} {% endif %} From 91a184b284a5cb4020e0a427534c941f55a2a138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller?= <9070224-W13R@users.noreply.gitlab.com> Date: Wed, 29 Jun 2022 19:08:21 +0200 Subject: [PATCH 18/93] Make the login overlay a bit more compact --- static/css/login.css | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/static/css/login.css b/static/css/login.css index 8a7fb03..346b4f9 100644 --- a/static/css/login.css +++ b/static/css/login.css @@ -70,9 +70,12 @@ form input[type="password"], form input[type="text"] { font-size: 1rem; margin: .1rem 0; } +form .horizontalButtonList { + margin-top: 1.5rem; +} .pinpad { - margin-top: 3rem; - margin-bottom: 2rem; + margin-top: 1.5rem; + margin-bottom: 0; display: flex; flex-direction: column; align-items: center; From 4fd02a84980025a780dfc069e85476907e97eb33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller?= <9070224-W13R@users.noreply.gitlab.com> Date: Wed, 29 Jun 2022 20:04:28 +0200 Subject: [PATCH 19/93] #7 fix broken login page for Webkit Browsers --- static/js/login.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/static/js/login.js b/static/js/login.js index 0f11ba0..df54187 100644 --- a/static/js/login.js +++ b/static/js/login.js @@ -1,4 +1,4 @@ -{ +(() => { // Define variables @@ -84,4 +84,4 @@ } } -} \ No newline at end of file +})() \ No newline at end of file From 4cd55136218d58c30c314e3e6193f484c63f1216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller?= <9070224-W13R@users.noreply.gitlab.com> Date: Wed, 29 Jun 2022 20:10:03 +0200 Subject: [PATCH 20/93] Bump version to 10 --- lib/env.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/env.sh b/lib/env.sh index 9eeb667..d11c933 100644 --- a/lib/env.sh +++ b/lib/env.sh @@ -2,5 +2,5 @@ export DJANGO_SK_ABS_FP="$(pwd)/config/secret_key.txt" export STATIC_FILES="$(pwd)/static/" -export APP_VERSION="9" +export APP_VERSION="10" export PYTHONPATH="$(pwd)/packages/" From 20d0ebfcf4fd0b219a67abdb85c0c660f1c4b3f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller?= <9070224-W13R@users.noreply.gitlab.com> Date: Tue, 5 Jul 2022 17:25:12 +0200 Subject: [PATCH 21/93] Swap x and 0 on pinpad (login overlay) --- application/app/templates/registration/login.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/app/templates/registration/login.html b/application/app/templates/registration/login.html index 14dc819..567d15d 100644 --- a/application/app/templates/registration/login.html +++ b/application/app/templates/registration/login.html @@ -45,8 +45,8 @@ - + From f2725845cf2421463651f5f98dae929ef63ae1dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller?= <9070224-W13R@users.noreply.gitlab.com> Date: Tue, 5 Jul 2022 17:42:50 +0200 Subject: [PATCH 22/93] hide the userlist in the background when showing the password overlay --- application/app/templates/registration/login.html | 2 +- static/js/login.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/application/app/templates/registration/login.html b/application/app/templates/registration/login.html index 567d15d..32b6ab0 100644 --- a/application/app/templates/registration/login.html +++ b/application/app/templates/registration/login.html @@ -64,7 +64,7 @@

{% translate "Choose your account" %}

-
+
    {% for user_ in user_list %}
  • diff --git a/static/js/login.js b/static/js/login.js index df54187..aea0630 100644 --- a/static/js/login.js +++ b/static/js/login.js @@ -5,11 +5,11 @@ let username_input; let password_input; let submit_button; - let username_display; let password_overlay; let pw_overlay_cancel; let userlist_buttons; let pinpad_buttons; + let userlist_container; // Add event listeners after DOM Content loaded @@ -23,6 +23,7 @@ submit_button = document.getElementById("submit_login"); password_overlay = document.getElementById("passwordOverlayContainer"); pw_overlay_cancel = document.getElementById("pwoCancel"); + userlist_container = document.getElementById("userlistContainer"); userlist_buttons = document.getElementsByClassName("userlistButton"); pinpad_buttons = document.getElementsByClassName("pinpadBtn"); @@ -59,15 +60,14 @@ window.scrollTo(0, 0); password_overlay.classList.remove("nodisplay"); - document.body.classList.add("overflowHidden"); - //password_input.focus(); + userlist_container.classList.add("nodisplay"); } function hide_password_overlay() { password_overlay.classList.add("nodisplay"); - document.body.classList.remove("overflowHidden"); + userlist_container.classList.remove("nodisplay"); password_input.value = ""; } From 117340683632d05fb9d7b838bd691049a012f8e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller?= <9070224-W13R@users.noreply.gitlab.com> Date: Tue, 5 Jul 2022 17:43:34 +0200 Subject: [PATCH 23/93] Bump version to 11 --- lib/env.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/env.sh b/lib/env.sh index d11c933..ba983e8 100644 --- a/lib/env.sh +++ b/lib/env.sh @@ -2,5 +2,5 @@ export DJANGO_SK_ABS_FP="$(pwd)/config/secret_key.txt" export STATIC_FILES="$(pwd)/static/" -export APP_VERSION="10" +export APP_VERSION="11" export PYTHONPATH="$(pwd)/packages/" From f5bf77fbed69ed262a92b37ef441de847fa7cef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller?= <9070224-W13R@users.noreply.gitlab.com> Date: Sat, 6 Aug 2022 17:33:31 +0200 Subject: [PATCH 24/93] Added auto-reload after 2 minutes when logged in, to force auto-logout --- application/app/templates/deposit.html | 1 + application/app/templates/history.html | 2 ++ application/app/templates/index.html | 2 ++ application/app/templates/order.html | 2 ++ application/app/templates/statistics.html | 2 ++ static/js/autoreload.js | 3 +++ 6 files changed, 12 insertions(+) create mode 100644 static/js/autoreload.js diff --git a/application/app/templates/deposit.html b/application/app/templates/deposit.html index 1093070..dac6950 100644 --- a/application/app/templates/deposit.html +++ b/application/app/templates/deposit.html @@ -35,5 +35,6 @@ + {% endblock %} diff --git a/application/app/templates/history.html b/application/app/templates/history.html index cdfa78f..ff43b23 100644 --- a/application/app/templates/history.html +++ b/application/app/templates/history.html @@ -32,5 +32,7 @@ {% else %} {% translate "No history." %} {% endif %} + + {% endblock %} diff --git a/application/app/templates/index.html b/application/app/templates/index.html index c639390..9836e32 100644 --- a/application/app/templates/index.html +++ b/application/app/templates/index.html @@ -44,4 +44,6 @@ {% endif %} + + {% endblock %} diff --git a/application/app/templates/order.html b/application/app/templates/order.html index 2f1d58f..5c72755 100644 --- a/application/app/templates/order.html +++ b/application/app/templates/order.html @@ -97,4 +97,6 @@ {% endif %} + + {% endblock %} diff --git a/application/app/templates/statistics.html b/application/app/templates/statistics.html index 9d26016..cc340fd 100644 --- a/application/app/templates/statistics.html +++ b/application/app/templates/statistics.html @@ -146,4 +146,6 @@
+ + {% endblock %} diff --git a/static/js/autoreload.js b/static/js/autoreload.js new file mode 100644 index 0000000..0c30078 --- /dev/null +++ b/static/js/autoreload.js @@ -0,0 +1,3 @@ +setInterval(() => { + location.reload(); +}, 1000*60*2); // reload after 2 minutes \ No newline at end of file From ca160781dd6702aacae1f0d91b8bfb9b6c87df01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller?= <9070224-W13R@users.noreply.gitlab.com> Date: Sat, 6 Aug 2022 18:56:39 +0200 Subject: [PATCH 25/93] Added support for profile pictures --- application/app/admin.py | 11 +++++--- application/app/models.py | 1 + .../app/templates/registration/login.html | 24 ++++++++-------- application/app/templates/userPanel.html | 26 +++++++++-------- static/css/login.css | 22 ++++++++++----- static/css/main.css | 11 ++++++-- static/profilepictures/default.svg | 28 +++++++++++++++++++ 7 files changed, 88 insertions(+), 35 deletions(-) create mode 100644 static/profilepictures/default.svg diff --git a/application/app/admin.py b/application/app/admin.py index 66b072a..7e81374 100644 --- a/application/app/admin.py +++ b/application/app/admin.py @@ -45,10 +45,13 @@ class CustomUserAdmin(UserAdmin): fieldsets_ = list((*UserAdmin.fieldsets,)) fieldsets_.insert(1, ( - "Balance", - {"fields": ("balance", "allow_order_with_negative_balance")}, - ) - ) + "Balance", + {"fields": ("balance", "allow_order_with_negative_balance")}, + )) + fieldsets_.insert(2, ( + "Profile Picture", + {"fields": ("profile_picture_filename",)}, + )) fieldsets = tuple(fieldsets_) list_display = ["username", "balance", "is_active", "allow_order_with_negative_balance"] diff --git a/application/app/models.py b/application/app/models.py index 7ce9370..370a0dd 100644 --- a/application/app/models.py +++ b/application/app/models.py @@ -20,6 +20,7 @@ class User(AbstractUser): balance = models.DecimalField(max_digits=8, decimal_places=2, default=0.00) allow_order_with_negative_balance = models.BooleanField(default=False) + profile_picture_filename = models.CharField(default="default.svg", max_length=25) def delete(self, *args, **kwargs): self.balance = 0 diff --git a/application/app/templates/registration/login.html b/application/app/templates/registration/login.html index 32b6ab0..af1f25c 100644 --- a/application/app/templates/registration/login.html +++ b/application/app/templates/registration/login.html @@ -2,6 +2,7 @@ {% extends "baseLayout.html" %} {% load i18n %} +{% load static %} {% block title %} {% translate "Drinks - Login" %} @@ -68,19 +69,20 @@
    {% for user_ in user_list %}
  • - - {% if user_.first_name %} + +
    + {% if user_.first_name %} - {% if user_.last_name %} - {{ user_.last_name }}, + {% if user_.last_name %} + {{ user_.last_name }}, + {% endif %} + + {{ user_.first_name }} + + {% else %} + {{ user_.username }} {% endif %} - - {{ user_.first_name }} - - {% else %} - {{ user_.username }} - {% endif %} - +
  • {% endfor %}
diff --git a/application/app/templates/userPanel.html b/application/app/templates/userPanel.html index eecaf88..b634cd3 100644 --- a/application/app/templates/userPanel.html +++ b/application/app/templates/userPanel.html @@ -1,18 +1,22 @@ {% load i18n %} +{% load static %}
- {% if user.first_name != "" %} - {% translate "User" %}: {{ user.first_name }} {{ user.last_name }} ({{ user.username }}) - {% else %} - {% translate "User" %}: {{ user.username }} - {% endif %} -  -  - {% if user.balance < 0.01 %} - {% translate "Balance" %}: {{ user.balance }}{{ currency_suffix }} - {% else %} - {% translate "Balance" %}: {{ user.balance }}{{ currency_suffix }} - {% endif %} + + + {% if user.first_name != "" %} + {% translate "User" %}: {{ user.first_name }} {{ user.last_name }} ({{ user.username }}) + {% else %} + {% translate "User" %}: {{ user.username }} + {% endif %} +  -  + {% if user.balance < 0.01 %} + {% translate "Balance" %}: {{ user.balance }}{{ currency_suffix }} + {% else %} + {% translate "Balance" %}: {{ user.balance }}{{ currency_suffix }} + {% endif %} +
Home diff --git a/static/css/login.css b/static/css/login.css index 346b4f9..6414c2d 100644 --- a/static/css/login.css +++ b/static/css/login.css @@ -25,14 +25,27 @@ main > h1 { justify-content: center; align-items: center; } -.userlist li { +.userlist > li { display: flex; width: 100%; align-items: center; justify-content: center; - padding: .8rem 1.1rem; margin-bottom: .5rem; + padding: 0 .5rem; +} +.userlist > li > img { + margin-right: auto; + margin-left: 0; + height: 2rem; + width: 2rem; +} +.userlist > li > div { + display: flex; + flex-grow: 1; + align-items: center; + justify-content: center; text-align: center; + padding: .8rem 1.1rem; } .userlistButton { font-size: 1.1rem; @@ -102,11 +115,6 @@ form .horizontalButtonList { .userlist { width: 100%; } - .userlist li { - width: 100%; - padding-left: 0; - padding-right: 0; - } .pinpad table tr td button { height: 4.2rem; width: 4.2rem; diff --git a/static/css/main.css b/static/css/main.css index fbc5d2a..c9cb878 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -67,10 +67,17 @@ main { align-items: center; margin-top: 1rem; font-size: 1rem; - width: 90%; + width: 94%; } -.userInfo span { +.userInfo > span { font-size: 1.1rem; + vertical-align: middle; +} +.userInfo > img { + vertical-align: middle; + width: 1.8rem; + height: 1.8rem; + margin: .5rem; } .userPanel > .horizontalButtonList { margin-left: auto; diff --git a/static/profilepictures/default.svg b/static/profilepictures/default.svg new file mode 100644 index 0000000..7138ef3 --- /dev/null +++ b/static/profilepictures/default.svg @@ -0,0 +1,28 @@ + + + + + + + + + + From 80b407069db12904f23191bc1df6f437a2f4356b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller?= <9070224-W13R@users.noreply.gitlab.com> Date: Sat, 6 Aug 2022 18:58:43 +0200 Subject: [PATCH 26/93] Bump version to 12 --- lib/env.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/env.sh b/lib/env.sh index ba983e8..8781ef1 100644 --- a/lib/env.sh +++ b/lib/env.sh @@ -2,5 +2,5 @@ export DJANGO_SK_ABS_FP="$(pwd)/config/secret_key.txt" export STATIC_FILES="$(pwd)/static/" -export APP_VERSION="11" +export APP_VERSION="12" export PYTHONPATH="$(pwd)/packages/" From 86ea7c0000cd7daf34ad21431119a21ae8300474 Mon Sep 17 00:00:00 2001 From: W13R <9070224-W13R@users.noreply.gitlab.com> Date: Sat, 15 Oct 2022 19:37:01 +0200 Subject: [PATCH 27/93] Added 'supply' page to create negative register transactions, updated translation --- application/app/admin.py | 4 + application/app/models.py | 1 + application/app/templates/supply.html | 61 +++++++ application/app/templates/userPanel.html | 3 + application/app/urls.py | 2 + application/app/views.py | 36 +++- application/locale/de/LC_MESSAGES/django.mo | Bin 3469 -> 3806 bytes application/locale/de/LC_MESSAGES/django.po | 177 ++++++++++++-------- static/css/supply.css | 6 + static/js/supply.js | 56 +++++++ 10 files changed, 278 insertions(+), 68 deletions(-) create mode 100644 application/app/templates/supply.html create mode 100644 static/css/supply.css create mode 100644 static/js/supply.js diff --git a/application/app/admin.py b/application/app/admin.py index 7e81374..e72e506 100644 --- a/application/app/admin.py +++ b/application/app/admin.py @@ -49,6 +49,10 @@ class CustomUserAdmin(UserAdmin): {"fields": ("balance", "allow_order_with_negative_balance")}, )) fieldsets_.insert(2, ( + "Supply", + {"fields": ("allowed_to_supply",)}, + )) + fieldsets_.insert(3, ( "Profile Picture", {"fields": ("profile_picture_filename",)}, )) diff --git a/application/app/models.py b/application/app/models.py index 370a0dd..b92672c 100644 --- a/application/app/models.py +++ b/application/app/models.py @@ -21,6 +21,7 @@ class User(AbstractUser): balance = models.DecimalField(max_digits=8, decimal_places=2, default=0.00) allow_order_with_negative_balance = models.BooleanField(default=False) profile_picture_filename = models.CharField(default="default.svg", max_length=25) + allowed_to_supply = models.BooleanField(default=False) def delete(self, *args, **kwargs): self.balance = 0 diff --git a/application/app/templates/supply.html b/application/app/templates/supply.html new file mode 100644 index 0000000..0f62ad5 --- /dev/null +++ b/application/app/templates/supply.html @@ -0,0 +1,61 @@ +{% extends "baseLayout.html" %} + +{% load i18n %} +{% load l10n %} + +{% block title %} +{% translate "Drinks - Supply" %} +{% endblock %} + +{% block headAdditional %} + + +{% endblock %} + +{% block heading %} + {% translate "Supply" %} +{% endblock %} + +{% block content %} + + {% if user.is_superuser or user.allowed_to_supply %} + +
+ {% csrf_token %} + +
+
{% translate "Description" %}:
+ +
+ +
+
{% translate "Price" %} ({{ currency_suffix }}):
+
+ +
+
+ +
+ + + +
+ + + + + {% else %} + +
+

{% translate "You are not allowed to view this site." %}

+ {% translate "back" %} +
+ + {% endif %} + + + +{% endblock %} diff --git a/application/app/templates/userPanel.html b/application/app/templates/userPanel.html index b634cd3..447c2d8 100644 --- a/application/app/templates/userPanel.html +++ b/application/app/templates/userPanel.html @@ -32,6 +32,9 @@ {% if user.is_superuser or user.is_staff %} Admin Panel {% endif %} + {% if user.is_superuser or user.allowed_to_supply %} + {% translate "Supply" %} + {% endif %} {% translate "Change Password" %}
diff --git a/application/app/urls.py b/application/app/urls.py index c7a221a..e720876 100644 --- a/application/app/urls.py +++ b/application/app/urls.py @@ -10,6 +10,7 @@ urlpatterns = [ path('history/', views.history), path('deposit/', views.deposit), path('statistics/', views.statistics), + path('supply/', views.supply), path('accounts/login/', views.login_page, name="login"), path('accounts/logout/', auth_views.LogoutView.as_view(), name='logout'), path('accounts/password_change/', auth_views.PasswordChangeView.as_view(), name='password_change'), @@ -18,5 +19,6 @@ urlpatterns = [ # API # path('api/order-drink', views.api_order_drink), path('api/deposit', views.api_deposit), + path('api/supply', views.api_supply) #path('api/get-statistics', views.api_get_statistics) ] \ No newline at end of file diff --git a/application/app/views.py b/application/app/views.py index 152d8bd..8511249 100644 --- a/application/app/views.py +++ b/application/app/views.py @@ -103,6 +103,10 @@ def statistics(request): } return render(request, "statistics.html", context) +@login_required +def supply(request): + return render(request, "supply.html") + @login_required def redirect_home(request): return HttpResponseRedirect("/") @@ -132,7 +136,7 @@ def api_order_drink(request): else: return HttpResponse("notAvailable", status=400) - else: raise Exception("Balance below zero.") + else: raise Exception("Unexpected input or missing privileges.") except Exception as e: print(f"An exception occured while processing an order: User: {user.username} - Exception: {e}", file=sys.stderr) @@ -163,5 +167,33 @@ def api_deposit(request): else: raise Exception("Deposit amount too big or small.") except Exception as e: - print(f"An exception occured while processing an transaction: User: {user.username} - Exception: {e}", file=sys.stderr) + print(f"An exception occured while processing a transaction: User: {user.username} - Exception: {e}", file=sys.stderr) + return HttpResponse(b"", status=500) + +@login_required +def api_supply(request): + + # check request -> supply + + user = request.user + + try: + + price = decimal.Decimal(request.POST["supplyPrice"]) + description = str(request.POST["supplyDescription"]) + + if 0.00 < price < 9999.99 and (user.allowed_to_supply or user.is_superuser): + # create transaction + RegisterTransaction.objects.create( + transaction_sum=-price, + comment=f"Supply: {description}", + is_user_deposit=False, + user=user + ) + # + return HttpResponse("success", status=200) + else: raise Exception("Unexpected input or missing privileges.") + + except Exception as e: + print(f"An exception occured while processing a supply transaction: User: {user.username} - Exception: {e}", file=sys.stderr) return HttpResponse(b"", status=500) diff --git a/application/locale/de/LC_MESSAGES/django.mo b/application/locale/de/LC_MESSAGES/django.mo index 07c684c8c574ed25adf7f9061611ea3ad5285e44..1f4683e4dba324f38b3068033447107f11c95ead 100644 GIT binary patch delta 1595 zcmYk+TWC~A9LMpA=GJ86B{p7@I;mzgO^h{F6RV{lYEfH=ET}IQH_0S9WOEYEp7j!> zt0)S=LSd<3iDtmC4P_fqPrNNLCWTXTxlq=Y8B>AH_#tk4c2kM7kU^VWs}Cy+n$2NxaDKd9%=P)9TE+h5@x z>Sd%)6Lz6CbO4pXbT#?c03i)Z^%-O><|3;7GU`nKL=F4^_0m1}&);~f7)=?o-cHnp zy08fkqQ?CWx8ONn|2skcKcV3s4NGwbS+tqQ8^x_zhT2&YYq1rX(|qaM_xk!iY^D7W zYN9dx3=6msCsCPvi|etT7sle(d2Te}5NgH8P$@cznrIA_x(lc?zJ!`!9F>_XzJ43E z&`DJPhp2u}krOt{2_2ov3ZjkBQRh3jyes;CHMq)}S&G*=T$d3_NWxvhe5e4C3)~>Uu+{j4gc;RsQPfeyP3VNI!agp5}yCIW`({YfEgPyEO z<*3g7vbG|*%BCY{!{OMbGnwI|uGhxH_DJB4+IS$y+H4TJw!+4WN9EaE_fQZ|%&pAN zNo;2Y1Ca~5b76nsRMq_@U%5EC^J_ThSVi$+y01^q_Et|78WYLt_uF8;raR6w&TS^m%0_KQ8*9@1D95NpAFC`3q=MQ+wX01K7)59UxoB0J zOH@!$)TTuQO|=LVqKJ@L8H7+sXhG1*ASjCJ|6GsI;lAg0&-LE(@t!lzG+)VNV-~%k+1g^wSScAWCGe%=(ORr2-A23>+vM= ze%VI2;j%|mdhsbX;5aVFx5#Cmsnp?D=Wq0B`;4v*v$zbqojcs~{iuFVU^AXVF1t+C z!T5I7J$Q~<;R~$Acc_79F@;}H1ANCMdi1I!rBRuyN0MMYSi}-)A;+*C&*Cb)h04$q z^cdeJxS>ybiCi{GrGckV15CU22UH4YUHhB!hw~3Mv3*`*p`SdXwD5iryKn&4;yG0R z*Ri~vo7>!IMboGm&$$1~LbG=$=1AZBZ4~ z-$&HhnNN~`eV8EMvIUi*K4dXAhy^@^>hJ4>~ zPgX*$d^dLDo)r04$HP46!%*bkt4Jv zI{7-hi$#O$=UVQh($7pqd!lq|=K6o2)RBPj@IZK&l;&PFC|a4aq0`+)EEd)juCf(- z+(TtAODJ3VwWyFWeY%k960RY%|BZyoIzs8RN+Fhy1P5yF1+ng>_ diff --git a/application/locale/de/LC_MESSAGES/django.po b/application/locale/de/LC_MESSAGES/django.po index 22c05b2..997e989 100644 --- a/application/locale/de/LC_MESSAGES/django.po +++ b/application/locale/de/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-06-13 19:01+0200\n" +"POT-Creation-Date: 2022-10-15 19:20+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: Julian Müller (W13R)\n" "Language: DE\n" @@ -17,221 +17,266 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" -#: app/templates/admin/base_site.html:7 +#: application/app/templates/admin/base_site.html:7 msgid "Django site admin" msgstr "Django Administrator" -#: app/templates/admin/base_site.html:15 +#: application/app/templates/admin/base_site.html:15 msgid "Django administration" msgstr "Django Administration" -#: app/templates/baseLayout.html:41 +#: application/app/templates/baseLayout.html:41 msgid "An error occured. Please log out and log in again." msgstr "Ein Fehler ist aufgetreten. Bitte ab- und wieder anmelden." -#: app/templates/deposit.html:6 +#: application/app/templates/deposit.html:6 msgid "Drinks - Deposit" msgstr "Getränke - Einzahlen" -#: app/templates/deposit.html:14 app/templates/userPanel.html:19 +#: application/app/templates/deposit.html:14 +#: application/app/templates/userPanel.html:23 msgid "Deposit" msgstr "Einzahlen" -#: app/templates/deposit.html:23 +#: application/app/templates/deposit.html:23 msgid "Amount" msgstr "Summe" -#: app/templates/deposit.html:31 app/templates/order.html:72 -#: app/templates/registration/login.html:56 +#: application/app/templates/deposit.html:31 +#: application/app/templates/order.html:72 +#: application/app/templates/registration/login.html:57 +#: application/app/templates/supply.html:41 msgid "cancel" msgstr "Abbrechen" -#: app/templates/deposit.html:32 +#: application/app/templates/deposit.html:32 msgid "confirm" msgstr "Bestätigen" -#: app/templates/history.html:6 +#: application/app/templates/history.html:6 msgid "Drinks - History" msgstr "Getränke - Verlauf" -#: app/templates/history.html:14 app/templates/userPanel.html:25 +#: application/app/templates/history.html:14 +#: application/app/templates/userPanel.html:30 msgid "History" msgstr "Verlauf" -#: app/templates/history.html:22 +#: application/app/templates/history.html:22 msgid "last 30 actions" msgstr "letzte 30 Vorgänge" -#: app/templates/history.html:33 app/templates/statistics.html:41 -#: app/templates/statistics.html:61 app/templates/statistics.html:81 -#: app/templates/statistics.html:101 app/templates/statistics.html:121 -#: app/templates/statistics.html:141 +#: application/app/templates/history.html:33 +#: application/app/templates/statistics.html:41 +#: application/app/templates/statistics.html:61 +#: application/app/templates/statistics.html:81 +#: application/app/templates/statistics.html:101 +#: application/app/templates/statistics.html:121 +#: application/app/templates/statistics.html:141 msgid "No history." msgstr "Kein Verlauf verfügbar." -#: app/templates/index.html:6 +#: application/app/templates/index.html:6 msgid "Drinks - Home" msgstr "Getränke - Home" -#: app/templates/index.html:14 +#: application/app/templates/index.html:14 msgid "Available Drinks" msgstr "Verfügbare Getränke" -#: app/templates/index.html:27 app/templates/index.html:34 +#: application/app/templates/index.html:27 +#: application/app/templates/index.html:34 msgid "available" msgstr "verfügbar" -#: app/templates/index.html:43 +#: application/app/templates/index.html:43 msgid "No drinks available." msgstr "Es sind gerade keine Getränke verfügbar." -#: app/templates/order.html:7 +#: application/app/templates/order.html:7 msgid "Drinks - Order" msgstr "Getränke - Bestellen" -#: app/templates/order.html:16 +#: application/app/templates/order.html:16 +#: packages/django/forms/formsets.py:405 packages/django/forms/formsets.py:412 msgid "Order" msgstr "Bestellung" -#: app/templates/order.html:29 +#: application/app/templates/order.html:29 msgid "Drink" msgstr "Getränk" -#: app/templates/order.html:34 +#: application/app/templates/order.html:34 msgid "Price per Item" msgstr "Preis pro Getränk" -#: app/templates/order.html:40 +#: application/app/templates/order.html:40 msgid "Available" msgstr "Verfügbar" -#: app/templates/order.html:46 +#: application/app/templates/order.html:46 msgid "Count" msgstr "Anzahl" -#: app/templates/order.html:63 +#: application/app/templates/order.html:63 msgid "Sum" msgstr "Summe" -#: app/templates/order.html:73 +#: application/app/templates/order.html:73 msgid "order" msgstr "Bestellen" -#: app/templates/order.html:85 +#: application/app/templates/order.html:85 msgid "Your balance is too low to order a drink." msgstr "Dein Saldo ist zu niedrig um Getränke zu bestellen." -#: app/templates/order.html:86 app/templates/order.html:95 +#: application/app/templates/order.html:86 +#: application/app/templates/order.html:95 +#: application/app/templates/supply.html:54 msgid "back" msgstr "zurück" -#: app/templates/order.html:94 +#: application/app/templates/order.html:94 msgid "This drink is not available." msgstr "Dieses Getränk ist gerade nicht verfügbar." -#: app/templates/registration/logged_out.html:7 +#: application/app/templates/registration/logged_out.html:7 msgid "Drinks - Logged Out" msgstr "Getränke - Abgemeldet" -#: app/templates/registration/logged_out.html:17 +#: application/app/templates/registration/logged_out.html:17 msgid "Logged out! You will be redirected shortly." msgstr "Du wurdest abgemeldet und wirst in Kürze weitergeleitet." -#: app/templates/registration/logged_out.html:19 +#: application/app/templates/registration/logged_out.html:19 msgid "Click here if automatic redirection does not work." msgstr "" "Bitte klicke hier, wenn die automatische Weiterleitung nicht funktioniert." -#: app/templates/registration/login.html:7 +#: application/app/templates/registration/login.html:8 msgid "Drinks - Login" msgstr "Getränke - Anmeldung" -#: app/templates/registration/login.html:26 +#: application/app/templates/registration/login.html:27 msgid "Log in" msgstr "Anmelden" -#: app/templates/registration/login.html:28 +#: application/app/templates/registration/login.html:29 msgid "Password/PIN" msgstr "Passwort/PIN" -#: app/templates/registration/login.html:57 +#: application/app/templates/registration/login.html:58 msgid "login" msgstr "Anmelden" -#: app/templates/registration/login.html:65 +#: application/app/templates/registration/login.html:66 msgid "Choose your account" msgstr "Wähle deinen Account" -#: app/templates/statistics.html:6 +#: application/app/templates/statistics.html:6 msgid "Drinks - Statistics" msgstr "Getränke - Statistiken" -#: app/templates/statistics.html:15 app/templates/userPanel.html:26 +#: application/app/templates/statistics.html:15 +#: application/app/templates/userPanel.html:31 msgid "Statistics" msgstr "Statistiken" -#: app/templates/statistics.html:26 +#: application/app/templates/statistics.html:26 msgid "Your orders per drink" msgstr "Deine Bestellungen pro Getränk" -#: app/templates/statistics.html:30 app/templates/statistics.html:50 +#: application/app/templates/statistics.html:30 +#: application/app/templates/statistics.html:50 msgid "drink" msgstr "Getränk" -#: app/templates/statistics.html:31 app/templates/statistics.html:51 -#: app/templates/statistics.html:71 app/templates/statistics.html:91 -#: app/templates/statistics.html:111 app/templates/statistics.html:131 +#: application/app/templates/statistics.html:31 +#: application/app/templates/statistics.html:51 +#: application/app/templates/statistics.html:71 +#: application/app/templates/statistics.html:91 +#: application/app/templates/statistics.html:111 +#: application/app/templates/statistics.html:131 msgid "count" msgstr "Anzahl" -#: app/templates/statistics.html:46 +#: application/app/templates/statistics.html:46 msgid "All orders per drink" msgstr "Alle Bestellungen pro Getränk" -#: app/templates/statistics.html:66 +#: application/app/templates/statistics.html:66 msgid "Your orders per month (last 12 months)" msgstr "Deine Bestellungen pro Monat (letzte 12 Monate)" -#: app/templates/statistics.html:70 app/templates/statistics.html:90 +#: application/app/templates/statistics.html:70 +#: application/app/templates/statistics.html:90 msgid "month" msgstr "Monat" -#: app/templates/statistics.html:86 +#: application/app/templates/statistics.html:86 msgid "All orders per month (last 12 months)" msgstr "Alle Bestellungen pro Monat (letzte 12 Monate)" -#: app/templates/statistics.html:106 +#: application/app/templates/statistics.html:106 msgid "Your orders per weekday" msgstr "Deine Bestellungen pro Wochentag" -#: app/templates/statistics.html:110 app/templates/statistics.html:130 +#: application/app/templates/statistics.html:110 +#: application/app/templates/statistics.html:130 msgid "day" msgstr "Tag" -#: app/templates/statistics.html:126 +#: application/app/templates/statistics.html:126 msgid "All orders per weekday" msgstr "Alle Bestellungen pro Wochentag" -#: app/templates/userPanel.html:6 app/templates/userPanel.html:8 +#: application/app/templates/supply.html:7 +msgid "Drinks - Supply" +msgstr "Getränke - Beschaffung" + +#: application/app/templates/supply.html:16 +#: application/app/templates/userPanel.html:36 +msgid "Supply" +msgstr "Beschaffung" + +#: application/app/templates/supply.html:27 +msgid "Description" +msgstr "Beschreibung" + +#: application/app/templates/supply.html:32 +msgid "Price" +msgstr "Preis" + +#: application/app/templates/supply.html:42 +msgid "submit" +msgstr "Senden" + +#: application/app/templates/supply.html:53 +msgid "You are not allowed to view this site." +msgstr "Dir fehlt die Berechtigung, diese Seite anzuzeigen." + +#: application/app/templates/userPanel.html:9 +#: application/app/templates/userPanel.html:11 msgid "User" msgstr "Benutzer" -#: app/templates/userPanel.html:12 app/templates/userPanel.html:14 +#: application/app/templates/userPanel.html:15 +#: application/app/templates/userPanel.html:17 msgid "Balance" msgstr "Saldo" -#: app/templates/userPanel.html:22 -msgid "Account" -msgstr "Account" - -#: app/templates/userPanel.html:30 -msgid "Change Password" -msgstr "Passwort ändern" - -#: app/templates/userPanel.html:31 +#: application/app/templates/userPanel.html:24 msgid "Logout" msgstr "Abmelden" -#: app/views.py:47 +#: application/app/templates/userPanel.html:27 +msgid "Account" +msgstr "Account" + +#: application/app/templates/userPanel.html:38 +msgid "Change Password" +msgstr "Passwort ändern" + +#: application/app/views.py:47 msgid "Invalid username or password." msgstr "Benutzername oder Passwort ungültig." diff --git a/static/css/supply.css b/static/css/supply.css new file mode 100644 index 0000000..a149993 --- /dev/null +++ b/static/css/supply.css @@ -0,0 +1,6 @@ +form { + width: 24rem; +} +#supplyPrice { + width: 10rem; +} \ No newline at end of file diff --git a/static/js/supply.js b/static/js/supply.js new file mode 100644 index 0000000..054b08d --- /dev/null +++ b/static/js/supply.js @@ -0,0 +1,56 @@ +document.addEventListener("DOMContentLoaded", () => { + + // elements + + let supply_description = document.getElementById("supplyDescription"); + let supply_price = document.getElementById("supplyPrice"); + + let supply_form = document.getElementById("supplyForm"); + let status_info = document.getElementById("statusInfo"); + let supply_submit_button = document.getElementById("supplySubmitBtn"); + + // custom submit method + + supply_form.addEventListener("submit", (event) => { + + supply_submit_button.disabled = true; + + event.preventDefault(); // Don't do the default submit action! + + if (isNaN(parseFloat(supply_price.value)) || supply_description.value == "") { + status_info.innerText = "Please enter a description and price." + supply_submit_button.disabled = false; + } + + let xhr = new XMLHttpRequest(); + let formData = new FormData(supply_form); + + xhr.addEventListener("load", (event) => { + + status_ = event.target.status; + response_ = event.target.responseText; + + if (status_ == 200 && response_ == "success") { + status_info.innerText = "Success."; + window.location.replace("/"); + } + else { + status_info.classList.add("errorText"); + status_info.innerText = "An error occured."; + window.setTimeout(() => { window.location.reload() }, 5000); + } + + }) + + xhr.addEventListener("error", (event) => { + status_info.classList.add("errorText"); + status_info.innerText = "An error occured."; + window.setTimeout(() => { window.location.reload() }, 5000); + }) + + xhr.open("POST", "/api/supply"); + xhr.send(formData); + + }); + +}) \ No newline at end of file From 9f270c12b485e7ea4a4478fde379406910fbc661 Mon Sep 17 00:00:00 2001 From: W13R <9070224-W13R@users.noreply.gitlab.com> Date: Wed, 2 Nov 2022 21:55:36 +0100 Subject: [PATCH 28/93] Profile pictures are now handled by the application to mitigate possible directory traversals to other sub-directories of the static directory (Admins/Staff with the right to edit user accounts were able to set a path like ../static/favicon.png for the profile picture - this isn't a "i'm in, now i have root access and can hack your mom"-vulnerability, but better fix it before it evolves to one. or a dragon. it's too late for this crap.) --- .gitignore | 4 +++- .../app/templates/registration/login.html | 2 +- application/app/templates/userPanel.html | 2 +- application/app/urls.py | 3 ++- application/app/views.py | 24 +++++++++++++++++++ application/drinks_manager/settings.py | 2 ++ lib/env.sh | 1 + .../default.svg | 0 8 files changed, 34 insertions(+), 4 deletions(-) rename {static/profilepictures => profilepictures}/default.svg (100%) diff --git a/.gitignore b/.gitignore index 8db7fca..4f97b84 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ /archive/* /logs/* /packages/* +/profilepictures/* /temp /tmp __pycache__ @@ -12,4 +13,5 @@ __pycache__ !/config/config.sample.sh !/config/Caddyfile !/config/tls/ -!.gitkeep \ No newline at end of file +!/profilepictures/default.svg +!.gitkeep diff --git a/application/app/templates/registration/login.html b/application/app/templates/registration/login.html index af1f25c..765172e 100644 --- a/application/app/templates/registration/login.html +++ b/application/app/templates/registration/login.html @@ -69,7 +69,7 @@