From 1021a2c7e83d89a72343c7cd763dcdda3180765a Mon Sep 17 00:00:00 2001 From: DariusIII Date: Fri, 30 Mar 2018 23:25:50 +0200 Subject: [PATCH] Add initial BrowseController --- Changelog | 2 + .../Controllers/Auth/RegisterController.php | 4 +- app/Http/Controllers/BasePageController.php | 4 +- app/Http/Controllers/BrowseController.php | 69 +++++++++++++++++++ app/Http/Controllers/ProfileController.php | 2 + public/index.php | 2 - routes/web.php | 6 +- 7 files changed, 79 insertions(+), 10 deletions(-) create mode 100644 app/Http/Controllers/BrowseController.php diff --git a/Changelog b/Changelog index 41be40fd1..e7a0ef14c 100755 --- a/Changelog +++ b/Changelog @@ -1,3 +1,5 @@ +2018-03-30 DariusIII + * Chg: Add initial BrowseController 2018-03-29 DariusIII * Chg: Update themes, BasePage and Profile controllers * Chg: Update themes and use ForgottenPasswordController diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index 5241ac939..97548705a 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -145,13 +145,13 @@ class RegisterController extends Controller } $res = User::getByUsername($userName); - if ($res) { + if ($res !== null) { $error = 'Sorry, the username is already taken.'; break; } $res = User::getByEmail($email); - if ($res) { + if ($res !== null) { $error = 'Sorry, the email is already in use.'; break; } diff --git a/app/Http/Controllers/BasePageController.php b/app/Http/Controllers/BasePageController.php index d4df1512d..d75b2b3fa 100644 --- a/app/Http/Controllers/BasePageController.php +++ b/app/Http/Controllers/BasePageController.php @@ -109,7 +109,7 @@ class BasePageController extends Controller /** * @throws \Exception */ - public function setPrefs() + protected function setPrefs() { if (Auth::check()) { $this->userdata = Auth::user(); @@ -166,7 +166,7 @@ class BasePageController extends Controller */ public function show403($from_admin = false): void { - header('Location: '.($from_admin ? str_replace('/admin', '', WWW_TOP) : WWW_TOP).'/login?redirect='.urlencode($request->getRequestUri())); + header('Location: '.($from_admin ? str_replace('/admin', '', WWW_TOP) : WWW_TOP).'/login?redirect='.urlencode(\request()->getRequestUri())); exit(); } diff --git a/app/Http/Controllers/BrowseController.php b/app/Http/Controllers/BrowseController.php new file mode 100644 index 000000000..84b269ada --- /dev/null +++ b/app/Http/Controllers/BrowseController.php @@ -0,0 +1,69 @@ +middleware('auth'); + } + + /** + * @throws \Exception + */ + public function index() + { + $this->setPrefs(); + $releases = new Releases(['Settings' => $this->settings]); + + $category = -1; + + $grp = -1; + + $catarray = []; + $catarray[] = $category; + + $this->smarty->assign('category', $category); + + $offset = 0; + $orderby = ''; + + $results = $releases->getBrowseRange($catarray, $offset, config('nntmux.items_per_page'), $orderby, -1, $this->userdata['categoryexclusions'], $grp); + + $browsecount = $results[0]['_totalcount'] ?? 0; + + $this->smarty->assign( + [ + 'pagertotalitems' => $browsecount, + 'pageroffset'=> $offset, + 'pageritemsperpage'=> config('nntmux.items_per_page'), + 'pagerquerybase' => WWW_TOP.'/browse?t='.$category.'&g='.$grp.'&ob='.$orderby.'&offset=', + 'pagerquerysuffix' => '#results', + ] + ); + + $pager = $this->smarty->fetch('pager.tpl'); + $this->smarty->assign('pager', $pager); + + $covgroup = ''; + $this->smarty->assign('catname', 'All'); + + $this->smarty->assign('covgroup', $covgroup); + + $this->smarty->assign('lastvisit', $this->userdata['lastlogin']); + + $this->smarty->assign('results', $results); + + $this->meta_title = 'Browse Nzbs'; + $this->meta_keywords = 'browse,nzb,description,details'; + $this->meta_description = 'Browse for Nzbs'; + + $this->content = $this->smarty->fetch('browse.tpl'); + $this->pagerender(); + } +} diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index 55d3828c3..c3b5ac3a9 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -24,6 +24,7 @@ class ProfileController extends BasePageController public function __construct(Request $request) { parent::__construct($request); + $this->middleware('auth'); } /** @@ -33,6 +34,7 @@ class ProfileController extends BasePageController */ public function show(Request $request) { + $this->setPrefs(); $sab = new SABnzbd(); $userID = Auth::id(); diff --git a/public/index.php b/public/index.php index 5b705519f..442524c62 100644 --- a/public/index.php +++ b/public/index.php @@ -1,6 +1,4 @@ make(\Illuminate\Contracts\Http\Kernel::class); diff --git a/routes/web.php b/routes/web.php index 8339c5a06..089f16847 100644 --- a/routes/web.php +++ b/routes/web.php @@ -39,11 +39,9 @@ Route::post('/forgottenpassword', 'Auth\ForgotPasswordController@showLinkRequest Route::get('/resetpassword', 'Auth\ResetPasswordController@reset'); Route::post('/resetpassword', 'Auth\ResetPasswordController@reset'); -Route::get('/profile', 'ProfileController@show')->middleware('auth'); +Route::get('/profile', 'ProfileController@show'); -Route::get('/browse', function () { - redirect('/browse'); -})->middleware('auth'); +Route::get('/browse', 'BrowseController@index'); Route::get('/console', function () { redirect('/console');