From 73432fe3d98dc813890f88cfec43f8b54ca34fac Mon Sep 17 00:00:00 2001 From: DariusIII Date: Fri, 2 Feb 2018 10:29:40 +0100 Subject: [PATCH] Use replace getById user lookup with User model find built in function(does the same thing as custom function) --- Changelog | 2 ++ app/Models/User.php | 10 +++++----- nntmux/NZBVortex.php | 10 +++++----- public/admin/user-edit.php | 2 +- public/pages/BasePage.php | 5 ++++- public/pages/btc_payment.php | 2 +- public/pages/details.php | 2 +- public/pages/movies.php | 2 +- public/pages/profile.php | 4 ++-- public/pages/profileedit.php | 2 +- public/pages/queue.php | 2 +- public/pages/sendtoqueue.php | 6 +++--- 12 files changed, 27 insertions(+), 22 deletions(-) diff --git a/Changelog b/Changelog index 8708e5515..1986cd470 100755 --- a/Changelog +++ b/Changelog @@ -1,3 +1,5 @@ +2018-02-02 DariusIII + * Chg: Use replace getById user lookup with User model find built in function(does the same thing as custom function) 2018-02-01 DariusIII * Chg: Update sebastian/comparator to latest version * Chg: Use create method when adding users diff --git a/app/Models/User.php b/app/Models/User.php index 839cd4224..574fd5ca1 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -529,12 +529,12 @@ class User extends Authenticatable */ public static function getByIdAndRssToken($userID, $rssToken) { - $user = self::getById($userID); - if ($user === false) { + $user = self::query()->where('id', '=', $userID, true)->where('rsstoken', '=', $rssToken)->get(); + if ($user === null) { return false; } - return $user->rsstoken !== $rssToken ? false : $user; + return $user; } /** @@ -788,7 +788,7 @@ class User extends Authenticatable return true; } if (isset($_COOKIE['uid'], $_COOKIE['idh'])) { - $u = self::getById($_COOKIE['uid']); + $u = self::find($_COOKIE['uid']); if ((int) $u['user_roles_id'] !== self::ROLE_DISABLED && $_COOKIE['idh'] === self::hashSHA1($u['userseed'].$_COOKIE['uid'])) { self::login($_COOKIE['uid'], $_SERVER['REMOTE_ADDR']); @@ -845,7 +845,7 @@ class User extends Authenticatable */ public static function setCookies($userID): void { - $user = self::getById($userID); + $user = self::find($userID); $secure_cookie = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? '1' : '0'); setcookie('uid', $userID, time() + 2592000, '/', null, $secure_cookie, true); setcookie('idh', self::hashSHA1($user['userseed'].$userID), time() + 2592000, '/', null, $secure_cookie, true); diff --git a/nntmux/NZBVortex.php b/nntmux/NZBVortex.php index 629a414fb..8d532b866 100755 --- a/nntmux/NZBVortex.php +++ b/nntmux/NZBVortex.php @@ -86,7 +86,7 @@ final class NZBVortex $page = new Page; $host = $page->serverurl; - $data = User::getById(User::currentUserId()); + $data = User::find(User::currentUserId()); $url = sprintf('%sgetnzb/%s.nzb&i=%s&r=%s', $host, $nzb, $data['id'], $data['rsstoken']); $params = [ @@ -248,7 +248,7 @@ final class NZBVortex */ protected function login() { - $data = User::getById(User::currentUserId()); + $data = User::find(User::currentUserId()); $cnonce = generateUuid(); $hash = hash('sha256', sprintf('%s:%s:%s', $this->nonce, $cnonce, $data['nzbvortex_api_key']), true); $hash = base64_encode($hash); @@ -261,11 +261,11 @@ final class NZBVortex $response = $this->sendRequest('auth/login', $params); - if ('successful' == $response['loginResult']) { + if ('successful' === $response['loginResult']) { $this->session = $response['sessionID']; } - if ('failed' == $response['loginResult']) { + if ('failed' === $response['loginResult']) { } } @@ -280,7 +280,7 @@ final class NZBVortex */ protected function sendRequest($path, $params = []) { - $data = User::getById(User::currentUserId()); + $data = User::find(User::currentUserId()); $url = sprintf('%s/api', $data['nzbvortex_server_url']); $params = http_build_query($params); diff --git a/public/admin/user-edit.php b/public/admin/user-edit.php index 7ef3d028f..e553b3fb5 100644 --- a/public/admin/user-edit.php +++ b/public/admin/user-edit.php @@ -114,7 +114,7 @@ switch ($action) { if (isset($_GET['id'])) { $page->title = 'User Edit'; $id = $_GET['id']; - $user = User::getById($id); + $user = User::find($id); $page->smarty->assign('user', $user); } diff --git a/public/pages/BasePage.php b/public/pages/BasePage.php index dc02d3e0e..a69fda4e3 100644 --- a/public/pages/BasePage.php +++ b/public/pages/BasePage.php @@ -334,9 +334,12 @@ class BasePage $this->smarty->display($this->page_template); } + /** + * @throws \Exception + */ protected function setUserPreferences(): void { - $this->userdata = User::getById(User::currentUserId()); + $this->userdata = User::find(User::currentUserId()); $this->userdata['categoryexclusions'] = User::getCategoryExclusion(User::currentUserId()); $this->userdata['rolecategoryexclusions'] = RoleExcludedCategory::getRoleCategoryExclusion($this->userdata['user_roles_id']); diff --git a/public/pages/btc_payment.php b/public/pages/btc_payment.php index f1bdb6e58..818509114 100644 --- a/public/pages/btc_payment.php +++ b/public/pages/btc_payment.php @@ -14,7 +14,7 @@ $gateway_id = env('MYCELIUM_GATEWAY_ID'); $gateway_secret = env('MYCELIUM_GATEWAY_SECRET'); $userId = User::currentUserId(); -$user = User::getById($userId); +$user = User::find($userId); $action = $_REQUEST['action'] ?? 'view'; $donation = UserRole::query()->where('donation', '>', 0)->get(['id', 'name', 'donation', 'addyears']); $page->smarty->assign('donation', $donation); diff --git a/public/pages/details.php b/public/pages/details.php index e4bf03c1d..818bd1312 100644 --- a/public/pages/details.php +++ b/public/pages/details.php @@ -28,7 +28,7 @@ if (isset($_GET['id'])) { $releases = new Releases(['Settings' => $page->settings]); $re = new ReleaseExtra; $data = Release::getByGuid($_GET['id']); - $user = User::getById(User::currentUserId()); + $user = User::find(User::currentUserId()); $cpapi = $user['cp_api']; $cpurl = $user['cp_url']; $releaseRegex = ReleaseRegex::query()->where('releases_id', '=', $data['id'])->first(); diff --git a/public/pages/movies.php b/public/pages/movies.php index 9a5eff434..36a863926 100644 --- a/public/pages/movies.php +++ b/public/pages/movies.php @@ -21,7 +21,7 @@ if (isset($_REQUEST['t']) && array_key_exists($_REQUEST['t'], $mtmp)) { $category = $_REQUEST['t'] + 0; } -$user = User::getById(User::currentUserId()); +$user = User::find(User::currentUserId()); $cpapi = $user['cp_api']; $cpurl = $user['cp_url']; $page->smarty->assign('cpapi', $cpapi); diff --git a/public/pages/profile.php b/public/pages/profile.php index e55d5645c..c35918a28 100644 --- a/public/pages/profile.php +++ b/public/pages/profile.php @@ -41,7 +41,7 @@ if ($privileged || ! $privateProfiles) { $downloadlist = UserDownload::getDownloadRequestsForUser($userID); $page->smarty->assign('downloadlist', $downloadlist); -$data = User::getById($userID); +$data = User::find($userID); if (! $data) { $page->show404(); } @@ -56,7 +56,7 @@ $page->smarty->assign( [ 'apirequests' => UserRequest::getApiRequests($userID), 'grabstoday' => UserDownload::getDownloadRequests($userID), - 'userinvitedby' => $data['invitedby'] !== '' ? User::getById($data['invitedby']) : '', + 'userinvitedby' => $data['invitedby'] !== '' ? User::find($data['invitedby']) : '', 'user' => $data, 'privateprofiles' => $privateProfiles, 'publicview' => $publicView, diff --git a/public/pages/profileedit.php b/public/pages/profileedit.php index bda81c62a..93b3b5b3d 100644 --- a/public/pages/profileedit.php +++ b/public/pages/profileedit.php @@ -18,7 +18,7 @@ if (! User::isLoggedIn()) { $action = $_REQUEST['action'] ?? 'view'; $userid = User::currentUserId(); -$data = User::getById($userid); +$data = User::find($userid); if (! $data) { $page->show404(); } diff --git a/public/pages/queue.php b/public/pages/queue.php index 41e752d57..9c5388d40 100644 --- a/public/pages/queue.php +++ b/public/pages/queue.php @@ -9,7 +9,7 @@ if (! User::isLoggedIn()) { $page->show403(); } -$userData = User::getById(User::currentUserId()); +$userData = User::find(User::currentUserId()); if (! $userData) { $page->show404(); } diff --git a/public/pages/sendtoqueue.php b/public/pages/sendtoqueue.php index 4b7c74e26..249ec4e41 100644 --- a/public/pages/sendtoqueue.php +++ b/public/pages/sendtoqueue.php @@ -12,8 +12,8 @@ if (empty($_GET['id'])) { $page->show404(); } -$user = User::getById(User::currentUserId()); -if ($user['queuetype'] != 2) { +$user = User::find(User::currentUserId()); +if ((int) $user['queuetype'] !== 2) { $sab = new SABnzbd($page); if (empty($sab->url)) { $page->show404(); @@ -22,7 +22,7 @@ if ($user['queuetype'] != 2) { $page->show404(); } $sab->sendToSab($_GET['id']); -} elseif ($user['queuetype'] == 2) { +} elseif ((int) $user['queuetype'] === 2) { $nzbget = new NZBGet($page); $nzbget->sendURLToNZBGet($_GET['id']); }