From 7df482871e5630d2cc69cdbfde4af82051168ccf Mon Sep 17 00:00:00 2001 From: Tim Krehan Date: Sat, 27 Oct 2018 18:26:26 +0200 Subject: [PATCH 01/28] added settings icon --- cont/nav.php | 1 + pic/settings.svg | 1 + style/nav.css | 7 +++++++ 3 files changed, 9 insertions(+) create mode 100644 pic/settings.svg diff --git a/cont/nav.php b/cont/nav.php index 8025acb..c670412 100644 --- a/cont/nav.php +++ b/cont/nav.php @@ -2,6 +2,7 @@ From acb0f6c01ca675b88918f2779243cf8fe966b43f Mon Sep 17 00:00:00 2001 From: Krehan Tim Date: Mon, 29 Oct 2018 08:22:38 +0100 Subject: [PATCH 08/28] spelling error --- style/settings.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/style/settings.css b/style/settings.css index 4cc1b89..2ce0911 100644 --- a/style/settings.css +++ b/style/settings.css @@ -18,12 +18,12 @@ padding: 1em; } .change-attribute-input { - + } .value { padding: 1em; } -#safeButton { +#saveButton { margin: 1em; width: min-content; float: right; From 00eeaa4dd43e39b19ef05671f8ecc98ffe22cbb2 Mon Sep 17 00:00:00 2001 From: Krehan Tim Date: Mon, 29 Oct 2018 08:45:49 +0100 Subject: [PATCH 09/28] added export layout --- cont/settings.php | 9 +++++++-- style/master.css | 9 +++++++++ style/settings.css | 28 +++++++++++++++++++++------- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/cont/settings.php b/cont/settings.php index faeedc2..164e5f0 100644 --- a/cont/settings.php +++ b/cont/settings.php @@ -1,6 +1,5 @@

Settings

-

User

fetch_assoc(); ?>
-
+

User

+
Benutzername"> Email"> @@ -17,4 +17,9 @@
+
+

Import / Export

+

Hiermit werden alle Rezepte und sich zurzeit auf der Shoppingliste befindlichen Einträge als Download zur Verfügung gestellt. Diese Datei kann dann an anderer Stelle wieder Importiert werden, oder als Backup abgespeichert werden.

+ +
diff --git a/style/master.css b/style/master.css index 864a674..bb4d180 100644 --- a/style/master.css +++ b/style/master.css @@ -26,6 +26,15 @@ h2 { width: 80%; } +h3 { + font-size: 1.5em; + text-align: left; + margin-top: .5em; + padding-bottom: .5em; + border-bottom: 1px solid grey; + width: 75%; +} + .even { background-color: #565656; } diff --git a/style/settings.css b/style/settings.css index 2ce0911..a89a802 100644 --- a/style/settings.css +++ b/style/settings.css @@ -1,12 +1,26 @@ -.userprofile { - width: 30em; - max-width: 90%; - margin: 0 auto; +.settings { display: flex; + justify-content: flex-start; flex-direction: column; + flex-wrap: wrap; +} +.pane { border: 1px solid grey; border-radius: 5px; background-color: #ddd; + margin: 1em; + min-width: max-content; + max-width: 50%; +} +.userprofile-pane { + display: flex; + flex-direction: column; + justify-content: flex-start; +} +.userprofile { + width: 22em; + display: flex; + flex-direction: column; } .userprofile span { display: flex; @@ -18,13 +32,13 @@ padding: 1em; } .change-attribute-input { - + text-indent: 1em; + color: grey; } .value { padding: 1em; } #saveButton { + align-self: flex-end; margin: 1em; - width: min-content; - float: right; } From 1751316783becc94850e280a1fa2528e1095eb47 Mon Sep 17 00:00:00 2001 From: Krehan Tim Date: Mon, 29 Oct 2018 08:48:16 +0100 Subject: [PATCH 10/28] added import content --- cont/settings.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cont/settings.php b/cont/settings.php index 164e5f0..cfa2d9f 100644 --- a/cont/settings.php +++ b/cont/settings.php @@ -20,6 +20,8 @@

Import / Export

Hiermit werden alle Rezepte und sich zurzeit auf der Shoppingliste befindlichen Einträge als Download zur Verfügung gestellt. Diese Datei kann dann an anderer Stelle wieder Importiert werden, oder als Backup abgespeichert werden.

- + +

Der Import kann Benutzt werden, um alle Daten von einer exportierten Datei in diese Datenbankk einzupflegen. Hierbei werden nur die Einträge in der Shoppingliste, sowie die Rezepte beachtet. Die Benutzer bleiben unberührt!

+
From 83deda921676a265cb79f6a89e5a1decf2b20a21 Mon Sep 17 00:00:00 2001 From: Krehan Tim Date: Mon, 29 Oct 2018 08:55:24 +0100 Subject: [PATCH 11/28] added style --- cont/settings.php | 8 ++++++++ style/settings.css | 19 +++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/cont/settings.php b/cont/settings.php index cfa2d9f..0dfd854 100644 --- a/cont/settings.php +++ b/cont/settings.php @@ -17,6 +17,14 @@ +
+
+ Altes Passwort + Neues Passwort + Passwort bestätigen +
+ +

Import / Export

Hiermit werden alle Rezepte und sich zurzeit auf der Shoppingliste befindlichen Einträge als Download zur Verfügung gestellt. Diese Datei kann dann an anderer Stelle wieder Importiert werden, oder als Backup abgespeichert werden.

diff --git a/style/settings.css b/style/settings.css index a89a802..9bbfe54 100644 --- a/style/settings.css +++ b/style/settings.css @@ -1,7 +1,7 @@ .settings { display: flex; justify-content: flex-start; - flex-direction: column; + flex-direction: row; flex-wrap: wrap; } .pane { @@ -10,7 +10,7 @@ background-color: #ddd; margin: 1em; min-width: max-content; - max-width: 50%; + max-width: 45%; } .userprofile-pane { display: flex; @@ -22,11 +22,26 @@ display: flex; flex-direction: column; } +.userpassword-pane { + display: flex; + flex-direction: column; + justify-content: flex-start; +} +.userpassword { + width: 22em; + display: flex; + flex-direction: column; +} .userprofile span { display: flex; flex-direction: row; align-items: center; } +.userpassword span { + display: flex; + flex-direction: row; + align-items: center; +} .attribute { width: 6em; padding: 1em; From 372e5499a4c71106b1f04c760b7f7265cddbae94 Mon Sep 17 00:00:00 2001 From: Matthias Kalb Date: Mon, 29 Oct 2018 13:59:41 +0100 Subject: [PATCH 12/28] minor format changes --- cont/settings.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cont/settings.php b/cont/settings.php index 0dfd854..cd5a7b6 100644 --- a/cont/settings.php +++ b/cont/settings.php @@ -11,17 +11,17 @@

User

- Benutzername"> - Email"> + Benutzername"> + Email"> Letzter Login
- Altes Passwort - Neues Passwort - Passwort bestätigen + Altes Passwort + Neues Passwort + Passwort bestätigen
@@ -29,7 +29,7 @@

Import / Export

Hiermit werden alle Rezepte und sich zurzeit auf der Shoppingliste befindlichen Einträge als Download zur Verfügung gestellt. Diese Datei kann dann an anderer Stelle wieder Importiert werden, oder als Backup abgespeichert werden.

-

Der Import kann Benutzt werden, um alle Daten von einer exportierten Datei in diese Datenbankk einzupflegen. Hierbei werden nur die Einträge in der Shoppingliste, sowie die Rezepte beachtet. Die Benutzer bleiben unberührt!

+

Der Import kann Benutzt werden, um alle Daten von einer exportierten Datei in diese Datenbank einzupflegen. Hierbei werden nur die Einträge in der Shoppingliste, sowie die Rezepte beachtet. Die Benutzer bleiben unberührt!

From 5c122eff9c2af12c90e5c320b768d4f146e112fc Mon Sep 17 00:00:00 2001 From: Tim Krehan Date: Mon, 29 Oct 2018 19:48:59 +0100 Subject: [PATCH 13/28] added som style and empty settings.js --- bin/settings.js | 0 cont/settings.php | 2 +- style/settings.css | 4 +++- 3 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 bin/settings.js diff --git a/bin/settings.js b/bin/settings.js new file mode 100644 index 0000000..e69de29 diff --git a/cont/settings.php b/cont/settings.php index cd5a7b6..b9873a4 100644 --- a/cont/settings.php +++ b/cont/settings.php @@ -29,7 +29,7 @@

Import / Export

Hiermit werden alle Rezepte und sich zurzeit auf der Shoppingliste befindlichen Einträge als Download zur Verfügung gestellt. Diese Datei kann dann an anderer Stelle wieder Importiert werden, oder als Backup abgespeichert werden.

-

Der Import kann Benutzt werden, um alle Daten von einer exportierten Datei in diese Datenbank einzupflegen. Hierbei werden nur die Einträge in der Shoppingliste, sowie die Rezepte beachtet. Die Benutzer bleiben unberührt!

+

Der Import kann benutzt werden, um alle Daten von einer exportierten Datei in diese Datenbank einzupflegen. Hierbei werden nur die Einträge in der Shoppingliste, sowie die Rezepte beachtet. Die Benutzer bleiben unberührt!

diff --git a/style/settings.css b/style/settings.css index 9bbfe54..ca4ba74 100644 --- a/style/settings.css +++ b/style/settings.css @@ -8,9 +8,11 @@ border: 1px solid grey; border-radius: 5px; background-color: #ddd; - margin: 1em; + margin: 1%; + width: auto; min-width: max-content; max-width: 45%; + height: max-content; } .userprofile-pane { display: flex; From 426b83f36419fb8c17368386807772db0fab808f Mon Sep 17 00:00:00 2001 From: Tim Krehan Date: Mon, 29 Oct 2018 19:57:40 +0100 Subject: [PATCH 14/28] added some js --- bin/settings.js | 7 +++++++ cont/settings.php | 9 +++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/bin/settings.js b/bin/settings.js index e69de29..b246730 100644 --- a/bin/settings.js +++ b/bin/settings.js @@ -0,0 +1,7 @@ +$(document).ready(function(){ + $("#username-input").focus(function(){$(this).css("color", "black");}); + $("#mail-input").focus(function(){$(this).css("color", "black");}); + $("#userSaveButton").click(function(){ + + }); +}); diff --git a/cont/settings.php b/cont/settings.php index b9873a4..a1a5cc3 100644 --- a/cont/settings.php +++ b/cont/settings.php @@ -1,3 +1,4 @@ +

Settings

User
- Benutzername"> - Email"> + Benutzername"> + Email"> Letzter Login
- +
@@ -23,7 +24,7 @@ Neues Passwort Passwort bestätigen
- +

Import / Export

From e7e5773762b10d5ed5c6d4e9a1b7cd76ff13bc75 Mon Sep 17 00:00:00 2001 From: Tim Krehan Date: Mon, 29 Oct 2018 21:12:53 +0100 Subject: [PATCH 15/28] added button stlye --- style/settings.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/style/settings.css b/style/settings.css index ca4ba74..7d19e53 100644 --- a/style/settings.css +++ b/style/settings.css @@ -55,7 +55,7 @@ .value { padding: 1em; } -#saveButton { +#passwordSaveButton, #userSaveButton { align-self: flex-end; margin: 1em; } From 406c5d9e0ad6bee23ee492a22871b33a0af33579 Mon Sep 17 00:00:00 2001 From: Tim Krehan Date: Mon, 29 Oct 2018 22:14:56 +0100 Subject: [PATCH 16/28] implemented export function --- bin/settings.js | 15 +++++++++++++-- cont/settings.php | 5 +++-- php/edit-recipes.php | 6 ++++++ style/master.css | 1 + 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/bin/settings.js b/bin/settings.js index b246730..4dbf2bc 100644 --- a/bin/settings.js +++ b/bin/settings.js @@ -1,7 +1,18 @@ +function downloadObjectAsJson(exportObj, exportName){ + var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(exportObj)); + var downloadAnchorNode = document.createElement('a'); + downloadAnchorNode.setAttribute("href", dataStr); + downloadAnchorNode.setAttribute("download", exportName + ".json"); + document.body.appendChild(downloadAnchorNode); // required for firefox + downloadAnchorNode.click(); + downloadAnchorNode.remove(); +} $(document).ready(function(){ $("#username-input").focus(function(){$(this).css("color", "black");}); $("#mail-input").focus(function(){$(this).css("color", "black");}); - $("#userSaveButton").click(function(){ - + $("#export-recipe-button").click(function(){ + $.post("/php/edit-recipes.php", {function:"export"}, function(data){ + downloadObjectAsJson(data, "recipes"); + }); }); }); diff --git a/cont/settings.php b/cont/settings.php index a1a5cc3..07f0079 100644 --- a/cont/settings.php +++ b/cont/settings.php @@ -29,8 +29,9 @@

Import / Export

Hiermit werden alle Rezepte und sich zurzeit auf der Shoppingliste befindlichen Einträge als Download zur Verfügung gestellt. Diese Datei kann dann an anderer Stelle wieder Importiert werden, oder als Backup abgespeichert werden.

- + +

Der Import kann benutzt werden, um alle Daten von einer exportierten Datei in diese Datenbank einzupflegen. Hierbei werden nur die Einträge in der Shoppingliste, sowie die Rezepte beachtet. Die Benutzer bleiben unberührt!

- +
diff --git a/php/edit-recipes.php b/php/edit-recipes.php index fcf86e0..5d7040e 100644 --- a/php/edit-recipes.php +++ b/php/edit-recipes.php @@ -27,6 +27,12 @@ header(("Location: /recipe/".$_POST["id"])); break; + case 'export': + $book->fillCookbook(); + header("Content-type: text/json"); + echo json_encode($book); + break; + default: // code... break; diff --git a/style/master.css b/style/master.css index bb4d180..2bce375 100644 --- a/style/master.css +++ b/style/master.css @@ -62,6 +62,7 @@ h3 { font-weight: 800; background-color: #4CAF50; color: white; + cursor: pointer; } .hover:hover { From 84729d5912688b18e02bcec243fe5ddba1bef3a1 Mon Sep 17 00:00:00 2001 From: Tim Krehan Date: Mon, 29 Oct 2018 22:23:51 +0100 Subject: [PATCH 17/28] added export for list entries --- bin/settings.js | 7 ++++++- php/edit-list.php | 5 +++++ php/edit-recipes.php | 1 - 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/bin/settings.js b/bin/settings.js index 4dbf2bc..0b4768c 100644 --- a/bin/settings.js +++ b/bin/settings.js @@ -12,7 +12,12 @@ $(document).ready(function(){ $("#mail-input").focus(function(){$(this).css("color", "black");}); $("#export-recipe-button").click(function(){ $.post("/php/edit-recipes.php", {function:"export"}, function(data){ - downloadObjectAsJson(data, "recipes"); + downloadObjectAsJson(JSON.parse(data), "recipes"); + }); + }); + $("#export-list-button").click(function(){ + $.post("/php/edit-list.php", {function:"export"}, function(data){ + downloadObjectAsJson(JSON.parse(data), "list"); }); }); }); diff --git a/php/edit-list.php b/php/edit-list.php index e9237df..ede9866 100644 --- a/php/edit-list.php +++ b/php/edit-list.php @@ -19,6 +19,11 @@ case 'check': $shopping->check($_POST["id"], $_POST["status"]); + break; + + case 'export': + echo json_encode($shopping); + break; default: // code... diff --git a/php/edit-recipes.php b/php/edit-recipes.php index 5d7040e..857bda4 100644 --- a/php/edit-recipes.php +++ b/php/edit-recipes.php @@ -29,7 +29,6 @@ case 'export': $book->fillCookbook(); - header("Content-type: text/json"); echo json_encode($book); break; From 28e7d78de1eff7ad63ed68662fce46a03f7ab723 Mon Sep 17 00:00:00 2001 From: Krehan Tim Date: Fri, 9 Nov 2018 13:21:34 +0100 Subject: [PATCH 18/28] implemented user class --- cont/settings.php | 13 +++++-------- php/classes.user.php | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 php/classes.user.php diff --git a/cont/settings.php b/cont/settings.php index 07f0079..bf6f020 100644 --- a/cont/settings.php +++ b/cont/settings.php @@ -2,19 +2,16 @@

Settings

query($query); - $user = $result->fetch_assoc(); + include $_SESSION["docroot"].'/php/classes.user.php'; + $user = new user($_COOKIE["token"]); ?>

User

- Benutzername"> - Email"> - Letzter Login + Benutzername + Email + Letzter Loginlast_login; ?>
diff --git a/php/classes.user.php b/php/classes.user.php new file mode 100644 index 0000000..ac6cd03 --- /dev/null +++ b/php/classes.user.php @@ -0,0 +1,15 @@ +query($query); + $user = $result->fetch_assoc(); + $this->uid = $user["uid"]; + $this->username = $user["username"]; + $this->email = $user["email"]; + $this->last_login = $user["last_login"]; + } + } +?> From 3fceb49e47c845f624b9defab861bb4ba046a60b Mon Sep 17 00:00:00 2001 From: Krehan Tim Date: Fri, 9 Nov 2018 15:16:36 +0100 Subject: [PATCH 19/28] Added Password Change and implemented user change in php class --- bin/settings.js | 41 +++++++++++++++++++++++++++++++++++++++++ cont/settings.php | 11 ++++++----- index.php | 2 ++ php/classes.user.php | 25 +++++++++++++++++++++++-- php/edit-user.php | 16 ++++++++++++++++ 5 files changed, 88 insertions(+), 7 deletions(-) create mode 100644 php/edit-user.php diff --git a/bin/settings.js b/bin/settings.js index 0b4768c..4693a12 100644 --- a/bin/settings.js +++ b/bin/settings.js @@ -10,6 +10,47 @@ function downloadObjectAsJson(exportObj, exportName){ $(document).ready(function(){ $("#username-input").focus(function(){$(this).css("color", "black");}); $("#mail-input").focus(function(){$(this).css("color", "black");}); + + // change password + $("#old-password-input").focus(function(){$(this).css("color", "black");}); + $("#new-password-input").focus(function(){$(this).css("color", "black");}); + $("#check-password-input").focus(function(){$(this).css("color", "black");}); + $(".password-input").on("input", function(){ + if( + (($("#old-password-input").val()).length>0) && + (($("#new-password-input").val()).length>0) && + (($("#check-password-input").val()).length>0) && + ($("#new-password-input").val()==$("#check-password-input").val()) + ){ + $("#passwordSaveButton").prop("disabled", false); + $("#passwordSaveButton").removeClass("button-disabled"); + } + else{ + $("#passwordSaveButton").prop("disabled", true); + $("#passwordSaveButton").addClass("button-disabled"); + } + }); + $("#passwordSaveButton").click(function(){ + $.post("/php/edit-user.php", + { + function: "change-pw", + current: $("#old-password-input").val(), + new: $("#new-password-input").val() + }, + function(data){ + if(data==0){ + $("#old-password-input").val(""); + $("#new-password-input").val(""); + $("#check-password-input").val(""); + infoPopUp("Passwort erfolgreich geändert!"); + } + else { + infoPopUp("Altes Passwort Falsch!"); + } + } + ); + }); + $("#export-recipe-button").click(function(){ $.post("/php/edit-recipes.php", {function:"export"}, function(data){ downloadObjectAsJson(JSON.parse(data), "recipes"); diff --git a/cont/settings.php b/cont/settings.php index bf6f020..8e108e6 100644 --- a/cont/settings.php +++ b/cont/settings.php @@ -3,7 +3,8 @@

Settings

get_info($_COOKIE["token"]); ?>

User

@@ -17,11 +18,11 @@
- Altes Passwort - Neues Passwort - Passwort bestätigen + Altes Passwort + Neues Passwort + Passwort bestätigen
- +

Import / Export

diff --git a/index.php b/index.php index 6cfadee..eec069c 100644 --- a/index.php +++ b/index.php @@ -23,6 +23,7 @@ + Einkaufsliste @@ -80,5 +81,6 @@ echo "
"; if($site && ($site!="login")){include $_SESSION["docroot"].'/cont/nav.php';} ?> +
diff --git a/php/classes.user.php b/php/classes.user.php index ac6cd03..cd89b33 100644 --- a/php/classes.user.php +++ b/php/classes.user.php @@ -1,15 +1,36 @@ query($query); $user = $result->fetch_assoc(); $this->uid = $user["uid"]; $this->username = $user["username"]; $this->email = $user["email"]; $this->last_login = $user["last_login"]; + $this->salt = $user["salt"]; + $mysqli->close(); + } + + function change_password($current, $new){ + include $_SESSION["docroot"].'/php/hash.php'; + include $_SESSION["docroot"].'/php/connect.php'; + $current_pwhash = hash_password($current, $this->salt); + $query = "SELECT `uid` FROM `users` WHERE `uid` = $this->uid AND `password` = '$current_pwhash'"; + $result = $mysqli->query($query); + if($result->num_rows===1){ + $new_pwdhash = hash_password($new, $this->salt); + $mysqli->query("UPDATE `users` SET `password` = '$new_pwdhash' WHERE `users`.`uid` = $this->uid;"); + $mysqli->close(); + print_r("0"); + } + else{ + print_r("1"); + } } } ?> diff --git a/php/edit-user.php b/php/edit-user.php new file mode 100644 index 0000000..48c4f5f --- /dev/null +++ b/php/edit-user.php @@ -0,0 +1,16 @@ +get_info($_COOKIE["token"]); + + switch ($_POST["function"]) { + case 'change-pw': + $user->change_password($_POST["current"], $_POST["new"]); + break; + + default: + // code... + break; + } +?> From 5af2219bac5ff9e44a2d0d348e62d28cb57ee7f7 Mon Sep 17 00:00:00 2001 From: Krehan Tim Date: Fri, 9 Nov 2018 15:17:00 +0100 Subject: [PATCH 20/28] simplyfied popup texts as function --- bin/index.js | 5 +++++ bin/list.js | 10 ++-------- cont/list.php | 2 -- style/list.css | 30 ------------------------------ style/master.css | 40 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 47 insertions(+), 40 deletions(-) create mode 100644 bin/index.js diff --git a/bin/index.js b/bin/index.js new file mode 100644 index 0000000..b45b4f3 --- /dev/null +++ b/bin/index.js @@ -0,0 +1,5 @@ +function infoPopUp(infotext){ + $("#info-popup-text").text(infotext); + $("#info-popup-text").css("animation", "none"); + setTimeout(function(){$("#info-popup-text").css("animation", "fade 4s linear");}, 100); +} diff --git a/bin/list.js b/bin/list.js index 0dfe365..05bced1 100644 --- a/bin/list.js +++ b/bin/list.js @@ -9,14 +9,8 @@ $(document).ready(function(){ id: dataId, status: $(this).prop("checked") }, - success: function(){ - $("#saved font").css("animation", "none"); - setTimeout(function(){$("#saved font").css("animation", "fade 4s linear");}, 100); - }, - error: function(){ - $("#error font").css("animation", "none"); - setTimeout(function(){$("#error font").css("animation", "fade 6s linear");}, 100); - } + success: function(){infoPopUp("SAVED!");}, + error: function(){infoPopUp("Netzwerkfehler! Bitte aktualisieren.");} }); if($(this).prop("checked")){$("[data-id='"+dataId+"']").addClass("checked");} else{$("[data-id='"+dataId+"']").removeClass("checked");} diff --git a/cont/list.php b/cont/list.php index e512a47..7810c60 100644 --- a/cont/list.php +++ b/cont/list.php @@ -35,5 +35,3 @@ ?>
-
SAVED!
-
Netzwerkfehler!
Bitte aktualisieren.
diff --git a/style/list.css b/style/list.css index e522262..23aa14b 100644 --- a/style/list.css +++ b/style/list.css @@ -92,33 +92,3 @@ border-left: none; .list_row.odd.checked { border-left: 3px solid #888; } - -#saved, #error { - pointer-events: none; - position: fixed; - display: flex; - justify-content: center; - bottom: 2%; - margin: 0; - left: 0; - width: 100%; -} -#saved font, #error font { - color: #ffffff; - background-color: #000000; - padding: .1em .5em .2em; - border-radius: 50px; - opacity: 0; -} - -#error font { - padding: .1em 1em .2em; -} -@keyframes fade { - 0% { - opacity: 0; - } - 10% { - opacity: 1; - } -} diff --git a/style/master.css b/style/master.css index 2bce375..2553976 100644 --- a/style/master.css +++ b/style/master.css @@ -65,7 +65,47 @@ h3 { cursor: pointer; } +.button:hover { + background-color: #4CAFFF; +} + +.button-disabled { + background-color: grey; + cursor: not-allowed; +} + +.button-disabled:hover { + background-color: grey; +} + .hover:hover { background-color: #4CAF50; cursor: pointer; } + +#info-popup { + pointer-events: none; + position: fixed; + display: flex; + justify-content: center; + bottom: 2%; + margin: 0; + left: 0; + width: 100%; +} +#info-popup-text { + color: #ffffff; + background-color: #000000; + padding: .1em .5em .2em; + border-radius: 50px; + opacity: 0; +} + +@keyframes fade { + 0% { + opacity: 0; + } + 10% { + opacity: 1; + } +} From 2f3c8f73908a9df23a88e1014365a481973c2457 Mon Sep 17 00:00:00 2001 From: Krehan Tim Date: Fri, 9 Nov 2018 15:58:00 +0100 Subject: [PATCH 21/28] installation add user via class --- cont/adduser.php | 10 ++++++---- install/adduser.php | 10 ++++++---- php/classes.user.php | 20 ++++++++++++++++++++ php/edit-user.php | 8 +++++++- 4 files changed, 39 insertions(+), 9 deletions(-) diff --git a/cont/adduser.php b/cont/adduser.php index 7945db7..1934912 100644 --- a/cont/adduser.php +++ b/cont/adduser.php @@ -1,12 +1,14 @@ -

Benutzer hinzufügen

-
- - + + + +
+ + diff --git a/install/adduser.php b/install/adduser.php index 7945db7..1934912 100644 --- a/install/adduser.php +++ b/install/adduser.php @@ -1,12 +1,14 @@ -

Benutzer hinzufügen

-
- - + + + +
+ + diff --git a/php/classes.user.php b/php/classes.user.php index cd89b33..1391ca4 100644 --- a/php/classes.user.php +++ b/php/classes.user.php @@ -32,5 +32,25 @@ print_r("1"); } } + + function new($uname, $password){ + session_start(); + include $_SESSION["docroot"].'/php/connect.php'; + include $_SESSION["docroot"].'/php/hash.php'; + + $query = "SELECT `uid` FROM `users` WHERE `username` = '$uname'"; + $result = $mysqli->query($query); + if($result->num_rows==0){ + $salt = create_salt(); + $passhash = hash_password($password, $salt); + $query = "INSERT INTO `users` (`username`, `password`, `salt`, `last_login`) VALUES ('$uname', '$passhash', '$salt', CURRENT_TIMESTAMP);"; + $result = $mysqli->query($query); + unset($salt); + unset($password); + print_r(0); + } + else{print_r(1);} + $mysqli->close(); + } } ?> diff --git a/php/edit-user.php b/php/edit-user.php index 48c4f5f..4729fee 100644 --- a/php/edit-user.php +++ b/php/edit-user.php @@ -2,13 +2,19 @@ session_start(); include $_SESSION["docroot"].'/php/classes.user.php'; $user = new user; - $user->get_info($_COOKIE["token"]); + if($_POST["function"]!="new-user"){ + $user->get_info($_COOKIE["token"]); + } switch ($_POST["function"]) { case 'change-pw': $user->change_password($_POST["current"], $_POST["new"]); break; + case 'new-user': + $user->new($_POST["username"], $_POST["passwd"]); + break; + default: // code... break; From 8758254a0f0997f8a3810f8588b5a194f91996f5 Mon Sep 17 00:00:00 2001 From: Tim Krehan Date: Sat, 10 Nov 2018 16:52:47 +0100 Subject: [PATCH 22/28] adduser call via ajax --- bin/adduser.js | 25 +++++++++++++++++++++++++ cont/.htaccess | 4 ++-- cont/adduser.php | 13 ++++++------- install/adduser.php | 12 ++++++++---- php/adduser_action.php | 15 --------------- style/adduser.css | 5 +++++ 6 files changed, 46 insertions(+), 28 deletions(-) create mode 100644 bin/adduser.js delete mode 100644 php/adduser_action.php diff --git a/bin/adduser.js b/bin/adduser.js new file mode 100644 index 0000000..d074218 --- /dev/null +++ b/bin/adduser.js @@ -0,0 +1,25 @@ +$(document).ready(function(){ + $("#button_newuser").click(function(){ + $.post("/php/edit-user.php", + { + function: "new-user", + username: $("#text_user").val(), + passwd: $("#text_passwd").val() + }, + function(data){ + if(data==0){ + infoPopUp("Benutzer erfolgreich erstellt!"); + $("#text_user").val(""); + $("#text_passwd").val(""); + $("#adduser-button-done").removeClass("button-disabled"); + } + else { + infoPopUp("Fehler bei der Benutzeranlage!"); + } + } + ); + }); + $("#adduser-button-done").click(function(){ + window.location.href = "/"; + }); +}); diff --git a/cont/.htaccess b/cont/.htaccess index 6f56351..98e9e6d 100644 --- a/cont/.htaccess +++ b/cont/.htaccess @@ -1,4 +1,4 @@ # prevent access to these files while not logged in - -Require all denied + + Require all denied diff --git a/cont/adduser.php b/cont/adduser.php index 1934912..8516eba 100644 --- a/cont/adduser.php +++ b/cont/adduser.php @@ -1,14 +1,13 @@ - - + + +

Benutzer hinzufügen

-
+
- - - - +
+ diff --git a/install/adduser.php b/install/adduser.php index 1934912..06fa697 100644 --- a/install/adduser.php +++ b/install/adduser.php @@ -2,13 +2,17 @@ + + +

Benutzer hinzufügen

-
+
- - +
+ - + +
diff --git a/php/adduser_action.php b/php/adduser_action.php deleted file mode 100644 index 3bd10d6..0000000 --- a/php/adduser_action.php +++ /dev/null @@ -1,15 +0,0 @@ -query("INSERT INTO `users` (`username`, `password`, `salt`, `last_login`) VALUES ('".$_POST["username"]."', '".$password."', '".$salt."', CURRENT_TIMESTAMP);"); -$mysqli->close(); - -unset($salt); -unset($password); -header("Location: /"); -?> diff --git a/style/adduser.css b/style/adduser.css index 8ba74e0..31df069 100644 --- a/style/adduser.css +++ b/style/adduser.css @@ -13,3 +13,8 @@ label { flex-direction: column; width: 50%; } +#adduser-button-done { + position: absolute; + bottom: 2em; + right: 2em; +} From f191979f9b528905a4f2ee21b37d95029c606caf Mon Sep 17 00:00:00 2001 From: Krehan Tim Date: Mon, 12 Nov 2018 08:50:04 +0100 Subject: [PATCH 23/28] removed commented section --- cont/adduser.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/cont/adduser.php b/cont/adduser.php index 8516eba..0f98a8d 100644 --- a/cont/adduser.php +++ b/cont/adduser.php @@ -1,6 +1,4 @@ - - From 413c026dc7d71017e8616ef28945a24c3b923713 Mon Sep 17 00:00:00 2001 From: Krehan Tim Date: Mon, 12 Nov 2018 09:02:43 +0100 Subject: [PATCH 24/28] fixed error during install, where "apache_get_modules" is not available --- install/install.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/install/install.php b/install/install.php index 3a4cc2c..0211e93 100644 --- a/install/install.php +++ b/install/install.php @@ -1,9 +1,9 @@ 0){ header("Location: /cont/error.php?id=php_modules&missing_mods=".serialize($missing_mods)); } @@ -28,7 +33,7 @@ if (!($_SESSION["docroot"])) header("Location: /"); exit; } - ?> +?> From ddbdcaa7281cc147592b302120d873501824f237 Mon Sep 17 00:00:00 2001 From: Krehan Tim Date: Mon, 12 Nov 2018 13:30:54 +0100 Subject: [PATCH 25/28] added .htaccess to prevent unauthorized access --- config/.htaccess | 5 ++++- php/.htaccess | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 php/.htaccess diff --git a/config/.htaccess b/config/.htaccess index b66e808..98e9e6d 100644 --- a/config/.htaccess +++ b/config/.htaccess @@ -1 +1,4 @@ -Require all denied +# prevent access to these files while not logged in + + Require all denied + diff --git a/php/.htaccess b/php/.htaccess new file mode 100644 index 0000000..da07521 --- /dev/null +++ b/php/.htaccess @@ -0,0 +1,16 @@ +# prevent access to these files while not logged in + + Require all denied + + + + Require all denied + + + + Require all denied + + + + Require all denied + From 2acc164365874850746d591ed1b65bca0404e92b Mon Sep 17 00:00:00 2001 From: Krehan Tim Date: Wed, 14 Nov 2018 16:08:36 +0100 Subject: [PATCH 26/28] implemented recipe import --- bin/settings.js | 47 ++++++++++++++++++++++++++++++++++++++++++ php/classes.recipe.php | 46 +++++++++++++++++++++++++++++++++++++++-- php/edit-recipes.php | 4 ++++ 3 files changed, 95 insertions(+), 2 deletions(-) diff --git a/bin/settings.js b/bin/settings.js index 4693a12..6f8071b 100644 --- a/bin/settings.js +++ b/bin/settings.js @@ -56,9 +56,56 @@ $(document).ready(function(){ downloadObjectAsJson(JSON.parse(data), "recipes"); }); }); + $("#export-list-button").click(function(){ $.post("/php/edit-list.php", {function:"export"}, function(data){ downloadObjectAsJson(JSON.parse(data), "list"); }); }); + + $("#import-button").click(function(){ + $('').on('change', function () { + var file = this.files[0]; + var reader = new FileReader(); + reader.onload = function(){ + var content = JSON.parse(reader.result); + if(content.sites!=null){ + $.post("/php/edit-recipes.php", + { + function: "import", + content: reader.result + }, + function(data){ + if(data==0){ + infoPopUp("Alle Rezepte erfolgreich Importiert!"); + } + else{ + infoPopUp("Nicht alle Rezepte konnten Importiert werden!"); + downloadObjectAsJson(JSON.parse(data), "failed_recipe_import.json"); + } + } + ); + } + else if(content.list!=null){ + $.post("/php/edit-list.php", + { + function: "import", + content: reader.result + }, + function(data){ + console.log(data); + // if(data==0){ + // infoPopUp("Alle Rezepte erfolgreich Importiert!"); + // } + // else{ + // infoPopUp("Nicht alle Rezepte konnten Importiert werden!"); + // downloadObjectAsJson(JSON.parse(data), "failed_recipe_import.json"); + // } + } + ); + } + }; + reader.readAsText(file); + }).click(); + }); }); diff --git a/php/classes.recipe.php b/php/classes.recipe.php index a4b1ec3..666f88d 100644 --- a/php/classes.recipe.php +++ b/php/classes.recipe.php @@ -20,6 +20,12 @@ } $mysqli->close(); } + function getID($Name){ + include $_SESSION["docroot"].'/php/connect.php'; + $result = $mysqli->query("SELECT `ID` FROM `Einheit` WHERE `Name` = '$Name'"); + $ID = $result->fetch_assoc(); + return $ID["ID"]; + } } class ingredient { @@ -89,15 +95,51 @@ $mysqli->close(); } + function importCookbook(){ + include $_SESSION["docroot"].'/php/connect.php'; + $units = new unitList(); + $failed_sites = array(); + $succeeded_sites = array(); + $import = json_decode($_POST["content"]); + if($import->sites!=null){ + foreach ($import->sites as $site) { + $result = $mysqli->query("SELECT * FROM `Rezept` WHERE `Name`='$site->Name'"); + if($result->num_rows>0){ + array_push($failed_sites, $site); + } + else{ + array_push($succeeded_sites, $site); + $Zutaten = array(); + foreach($site->Zutaten as $Zutat) { + $nZutat = null; + $nZutat["ID"] = $Zutat->ID; + $nZutat["Amount"] = $Zutat->Menge; + $nZutat["Unit"] = $units->getID($Zutat->Einheit); + $nZutat["Name"] = $Zutat->Name; + array_push($Zutaten, $nZutat); + } + $this->newRecipe($site->Name, $site->Dauer, $site->Beschreibung, $Zutaten); + } + } + if(sizeof($failed_sites)==0){ + print_r("0"); + } + else{ + print_r(json_encode($failed_sites)); + } + } + } + function newRecipe($Name, $Dauer, $Beschreibung, $Zutaten){ include $_SESSION["docroot"].'/php/connect.php'; - $mysqli->query("INSERT INTO Rezept (Name, Dauer, Beschreibung) VALUES ('$Name', '$Dauer', '$Beschreibung')"); + $mysqli->query("INSERT INTO `Rezept` (`Name`, `Dauer`, `Beschreibung`) VALUES ('$Name', '$Dauer', '$Beschreibung')"); $RezeptID = $mysqli->insert_id; foreach ($Zutaten as $Zutat) { $ZutatID = null; $result = $mysqli->query("SELECT ID FROM `Zutat` WHERE `Name` LIKE '".$Zutat["Name"]."'"); if($result->num_rows>0){ - while($item = $result->fetch_assoc()){$ZutatID = $item["ID"];} + $item = $result->fetch_assoc(); + $ZutatID = $item["ID"]; } else{ $mysqli->query("INSERT INTO `Zutat` (`Name`) VALUES ('".ucwords($Zutat["Name"])."')"); diff --git a/php/edit-recipes.php b/php/edit-recipes.php index 857bda4..aa068c6 100644 --- a/php/edit-recipes.php +++ b/php/edit-recipes.php @@ -32,6 +32,10 @@ echo json_encode($book); break; + case 'import': + $book->importCookbook(); + break; + default: // code... break; From 5f18b295a4838a3780ea32b3ce5a17411f6689eb Mon Sep 17 00:00:00 2001 From: Krehan Tim Date: Wed, 14 Nov 2018 16:25:50 +0100 Subject: [PATCH 27/28] added import for listitems (hopefully) --- bin/adduser.js | 4 ++-- bin/index.js | 4 ++-- bin/list.js | 4 ++-- bin/settings.js | 18 +++++++----------- php/classes.list.php | 17 +++++++++++++++++ php/edit-list.php | 4 ++++ 6 files changed, 34 insertions(+), 17 deletions(-) diff --git a/bin/adduser.js b/bin/adduser.js index d074218..d2cb4c7 100644 --- a/bin/adduser.js +++ b/bin/adduser.js @@ -8,13 +8,13 @@ $(document).ready(function(){ }, function(data){ if(data==0){ - infoPopUp("Benutzer erfolgreich erstellt!"); + infoPopUp("Benutzer erfolgreich erstellt!", 100); $("#text_user").val(""); $("#text_passwd").val(""); $("#adduser-button-done").removeClass("button-disabled"); } else { - infoPopUp("Fehler bei der Benutzeranlage!"); + infoPopUp("Fehler bei der Benutzeranlage!", 100); } } ); diff --git a/bin/index.js b/bin/index.js index b45b4f3..1e6efec 100644 --- a/bin/index.js +++ b/bin/index.js @@ -1,5 +1,5 @@ -function infoPopUp(infotext){ +function infoPopUp(infotext, timeout){ $("#info-popup-text").text(infotext); $("#info-popup-text").css("animation", "none"); - setTimeout(function(){$("#info-popup-text").css("animation", "fade 4s linear");}, 100); + setTimeout(function(){$("#info-popup-text").css("animation", "fade 4s linear");}, timeout); } diff --git a/bin/list.js b/bin/list.js index 05bced1..f469531 100644 --- a/bin/list.js +++ b/bin/list.js @@ -9,8 +9,8 @@ $(document).ready(function(){ id: dataId, status: $(this).prop("checked") }, - success: function(){infoPopUp("SAVED!");}, - error: function(){infoPopUp("Netzwerkfehler! Bitte aktualisieren.");} + success: function(){infoPopUp("SAVED!", 100);}, + error: function(){infoPopUp("Netzwerkfehler! Bitte aktualisieren.", 100);} }); if($(this).prop("checked")){$("[data-id='"+dataId+"']").addClass("checked");} else{$("[data-id='"+dataId+"']").removeClass("checked");} diff --git a/bin/settings.js b/bin/settings.js index 6f8071b..349910e 100644 --- a/bin/settings.js +++ b/bin/settings.js @@ -42,10 +42,10 @@ $(document).ready(function(){ $("#old-password-input").val(""); $("#new-password-input").val(""); $("#check-password-input").val(""); - infoPopUp("Passwort erfolgreich geändert!"); + infoPopUp("Passwort erfolgreich geändert!", 100); } else { - infoPopUp("Altes Passwort Falsch!"); + infoPopUp("Altes Passwort Falsch!", 100); } } ); @@ -77,10 +77,10 @@ $(document).ready(function(){ }, function(data){ if(data==0){ - infoPopUp("Alle Rezepte erfolgreich Importiert!"); + infoPopUp("Alle Rezepte erfolgreich Importiert!", 200); } else{ - infoPopUp("Nicht alle Rezepte konnten Importiert werden!"); + infoPopUp("Nicht alle Rezepte konnten Importiert werden!", 1000); downloadObjectAsJson(JSON.parse(data), "failed_recipe_import.json"); } } @@ -94,13 +94,9 @@ $(document).ready(function(){ }, function(data){ console.log(data); - // if(data==0){ - // infoPopUp("Alle Rezepte erfolgreich Importiert!"); - // } - // else{ - // infoPopUp("Nicht alle Rezepte konnten Importiert werden!"); - // downloadObjectAsJson(JSON.parse(data), "failed_recipe_import.json"); - // } + if(data==0){ + infoPopUp("Alle Listeneinträge erfolgreich Importiert!", 200); + } } ); } diff --git a/php/classes.list.php b/php/classes.list.php index 8b29ca1..8bf1a49 100644 --- a/php/classes.list.php +++ b/php/classes.list.php @@ -60,6 +60,15 @@ $mysqli->query("UPDATE `Einkauf` SET `Erledigt` = $status WHERE `Einkauf`.`ID` = $id"); $mysqli->close(); } + + function import(){ + $import = json_decode($_POST["content"]); + $units = new units(); + foreach($import->list as $item){ + $this->newItem($item->Anzahl, $units->getID($item->Einheit), $item->Name); + } + print_f("0"); + } } class unit { @@ -86,5 +95,13 @@ } $mysqli->close(); } + + function getID($Name){ + foreach($this->list as $units){ + if($units->Name==$Name){ + return $units->ID; + } + } + } } ?> diff --git a/php/edit-list.php b/php/edit-list.php index ede9866..82326c9 100644 --- a/php/edit-list.php +++ b/php/edit-list.php @@ -25,6 +25,10 @@ echo json_encode($shopping); break; + case 'import': + $shopping->import(); + break; + default: // code... break; From 5772c3f9f51ebd95bad2fbbe327a55a3ca094eba Mon Sep 17 00:00:00 2001 From: Krehan Tim Date: Wed, 14 Nov 2018 16:28:05 +0100 Subject: [PATCH 28/28] fixed double json extension while downloading error file --- bin/settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/settings.js b/bin/settings.js index 349910e..51164bb 100644 --- a/bin/settings.js +++ b/bin/settings.js @@ -81,7 +81,7 @@ $(document).ready(function(){ } else{ infoPopUp("Nicht alle Rezepte konnten Importiert werden!", 1000); - downloadObjectAsJson(JSON.parse(data), "failed_recipe_import.json"); + downloadObjectAsJson(JSON.parse(data), "failed_recipe_import"); } } );