From 1abe9c3e5f0cc95b90acbe518a30c116d3a5c2ef Mon Sep 17 00:00:00 2001 From: Jay Trees Date: Wed, 23 Feb 2022 09:36:54 +0100 Subject: [PATCH 1/3] Allow admins to log in as user --- src/classes/page.php | 9 +++++-- src/classes/user.php | 7 ++--- src/pages/login-as.php | 58 ++++++++++++++++++++++++++++++++++++++++++ src/pages/login.php | 9 +++---- 4 files changed, 73 insertions(+), 10 deletions(-) create mode 100644 src/pages/login-as.php diff --git a/src/classes/page.php b/src/classes/page.php index 618e1467..8bd164c5 100644 --- a/src/classes/page.php +++ b/src/classes/page.php @@ -219,8 +219,13 @@ class Page isLoggedIn()) { - ?> + if ($user && $user->isLoggedIn()) { ?> + power) { ?> + + + Login as + + Logout diff --git a/src/classes/user.php b/src/classes/user.php index 567d1758..21f8957f 100644 --- a/src/classes/user.php +++ b/src/classes/user.php @@ -31,9 +31,10 @@ class User global $database; - $user = $database->query('SELECT * FROM `users` - WHERE `id` = ' . $this->id . ';') - ->fetch(); + $user = $database + ->query('SELECT * FROM `users` + WHERE `id` = ' . $this->id . ';') + ->fetch(); $this->power = $user['power']; } diff --git a/src/pages/login-as.php b/src/pages/login-as.php new file mode 100644 index 00000000..e8e90c00 --- /dev/null +++ b/src/pages/login-as.php @@ -0,0 +1,58 @@ + + */ + +use wishthis\Page; + +$page = new Page(__FILE__, 'Login as'); + +if (isset($_POST['email'])) { + $email = $_POST['email']; + + $user = $database->query('SELECT * FROM `users` + WHERE `email` = "' . $email . '";') + ->fetch(); + + $success = false !== $user; + + if ($success) { + $_SESSION['user'] = $user; + + echo '
';
+        var_dump($user);
+        echo '
';
+    }
+}
+
+$page->header();
+$page->navigation();
+?>
+
+
+

title ?>

+ + + +
+
+
+ + +
+ + +
+
+
+
+ +footer(); diff --git a/src/pages/login.php b/src/pages/login.php index 24023789..71c9adf1 100644 --- a/src/pages/login.php +++ b/src/pages/login.php @@ -19,11 +19,10 @@ if (isset($_POST['email'], $_POST['password'])) { WHERE `email` = "' . $email . '" AND `password` = "' . $password . '" ;'); - $user = $database->query( - 'SELECT * FROM `users` - WHERE `email` = "' . $email . '" - AND `password` = "' . $password . '";' - )->fetch(); + $user = $database->query('SELECT * FROM `users` + WHERE `email` = "' . $email . '" + AND `password` = "' . $password . '";') + ->fetch(); $success = false !== $user; From 78ddc35b8d2fad788fe0d62dfa7459baade6ab23 Mon Sep 17 00:00:00 2001 From: Jay Trees Date: Wed, 23 Feb 2022 09:40:06 +0100 Subject: [PATCH 2/3] Fix Array to string conversion --- src/classes/wishlist.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/classes/wishlist.php b/src/classes/wishlist.php index 5912eb35..ae1c1a52 100644 --- a/src/classes/wishlist.php +++ b/src/classes/wishlist.php @@ -108,7 +108,7 @@ class Wishlist keywords) { ?>
- keywords ?> + keywords) ?>
From 80fc577ca4601d95806fe3acc57729b580e46352 Mon Sep 17 00:00:00 2001 From: Jay Trees Date: Wed, 23 Feb 2022 09:55:00 +0100 Subject: [PATCH 3/3] Fix cards not showing --- src/api/products.php | 2 +- src/api/wishlists.php | 2 +- src/assets/js/wishlist-view.js | 1 + src/classes/wishlist.php | 4 +++- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/api/products.php b/src/api/products.php index d7111af1..3456879d 100644 --- a/src/api/products.php +++ b/src/api/products.php @@ -42,6 +42,6 @@ switch ($_SERVER['REQUEST_METHOD']) { break; } -echo json_encode($response); header('Content-type: application/json; charset=utf-8'); +echo json_encode($response); die(); diff --git a/src/api/wishlists.php b/src/api/wishlists.php index b7d3dcf6..3c3a85a5 100644 --- a/src/api/wishlists.php +++ b/src/api/wishlists.php @@ -47,6 +47,6 @@ switch ($_SERVER['REQUEST_METHOD']) { break; } -echo json_encode($response); header('Content-type: application/json; charset=utf-8'); +echo json_encode($response); die(); diff --git a/src/assets/js/wishlist-view.js b/src/assets/js/wishlist-view.js index 895655fc..2cc9fc44 100644 --- a/src/assets/js/wishlist-view.js +++ b/src/assets/js/wishlist-view.js @@ -10,6 +10,7 @@ $(function() { on: 'now', onSuccess: function(response, element, xhr) { wishlists = response.results; + console.log(wishlists); element.dropdown({ values: wishlists, diff --git a/src/classes/wishlist.php b/src/classes/wishlist.php index ae1c1a52..b0ba2cac 100644 --- a/src/classes/wishlist.php +++ b/src/classes/wishlist.php @@ -149,6 +149,8 @@ class Wishlist