From a82420b17102b49ac9cb804dc45d623420313fc3 Mon Sep 17 00:00:00 2001 From: grandeljay Date: Fri, 17 Jun 2022 07:47:06 +0200 Subject: [PATCH] Refactor --- src/classes/cache/cache.php | 2 +- src/pages/register.php | 42 +++++++++++++++++++++++-------------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/classes/cache/cache.php b/src/classes/cache/cache.php index 4a5d901e..7bea6432 100644 --- a/src/classes/cache/cache.php +++ b/src/classes/cache/cache.php @@ -13,7 +13,7 @@ class Cache */ protected string $url; protected string $directory = ROOT . '/src/cache'; - protected int $maxAge = 2592000; // 30 days + protected int $maxAge = 2592000; // 30 days protected function getAge(): int { diff --git a/src/pages/register.php b/src/pages/register.php index bd7b5f14..47a31523 100644 --- a/src/pages/register.php +++ b/src/pages/register.php @@ -24,10 +24,10 @@ if (isset($_POST['email'], $_POST['password']) && !empty($_POST['planet'])) { $users ); - $isHuman = false; - $planet = strtolower($_POST['planet']); - $planetName = strtoupper($planet[0]) . substr($planet, 1); - $planets = array( + $isHuman = false; + $planet = strtolower($_POST['planet']); + $planetName = strtoupper($planet[0]) . substr($planet, 1); + $planets = array( strtolower(__('Mercury')), strtolower(__('Venus')), strtolower(__('Earth')), @@ -61,19 +61,23 @@ if (isset($_POST['email'], $_POST['password']) && !empty($_POST['planet'])) { * Password reset */ $user = $database - ->query('SELECT * FROM `users` - WHERE `email` = "' . $_GET['password-reset'] . '" - AND `password_reset_token` = "' . $_GET['token'] . '";') + ->query( + 'SELECT * FROM `users` + WHERE `email` = "' . $_GET['password-reset'] . '" + AND `password_reset_token` = "' . $_GET['token'] . '";' + ) ->fetch(); - if ($user) { + if (false !== $user) { if (time() > $user['password_reset_valid_until']) { $database - ->query('UPDATE `users` + ->query( + 'UPDATE `users` SET `password` = "' . User::generatePassword($_POST['password']) . '", `password_reset_token` = NULL, `password_reset_valid_until` = NULL - WHERE `id` = ' . $user['id'] . ';'); + WHERE `id` = ' . $user['id'] . ';' + ); $page->messages[] = Page::success( 'Password has been successfully reset for ' . $_GET['password-reset'] . '.', @@ -90,7 +94,8 @@ if (isset($_POST['email'], $_POST['password']) && !empty($_POST['planet'])) { * Register */ if (0 === count($users)) { - $database->query('INSERT INTO `users` + $database->query( + 'INSERT INTO `users` ( `email`, `password`, @@ -100,7 +105,8 @@ if (isset($_POST['email'], $_POST['password']) && !empty($_POST['planet'])) { "' . User::generatePassword($_POST['password']) . '", 100 ) - ;'); + ;' + ); $userRegistered = true; } else { if (in_array($_POST['email'], $emails)) { @@ -109,7 +115,8 @@ if (isset($_POST['email'], $_POST['password']) && !empty($_POST['planet'])) { __('Invalid email address') ); } else { - $database->query('INSERT INTO `users` + $database->query( + 'INSERT INTO `users` ( `email`, `password` @@ -117,7 +124,8 @@ if (isset($_POST['email'], $_POST['password']) && !empty($_POST['planet'])) { "' . $_POST['email'] . '", "' . User::generatePassword($_POST['password']) . '" ) - ;'); + ;' + ); $userRegistered = true; $page->messages[] = Page::success(__('Your account was successfully created.'), __('Success')); @@ -133,7 +141,8 @@ if (isset($_POST['email'], $_POST['password']) && !empty($_POST['planet'])) { $wishlistName = __('My hopes and dreams'); $database - ->query('INSERT INTO `wishlists` + ->query( + 'INSERT INTO `wishlists` ( `user`, `name`, @@ -143,7 +152,8 @@ if (isset($_POST['email'], $_POST['password']) && !empty($_POST['planet'])) { "' . $wishlistName . '", "' . sha1(time() . $userID . $wishlistName) . '" ) - ;'); + ;' + ); } } else { $page->messages[] = Page::error(