diff --git a/Blacklight/http/BasePage.php b/Blacklight/http/BasePage.php index 991880189..0bdd73090 100644 --- a/Blacklight/http/BasePage.php +++ b/Blacklight/http/BasePage.php @@ -121,17 +121,16 @@ class BasePage // Buffer settings/DB connection. $this->settings = new Settings(); $this->pdo = new DB(); - $this->smarty = new Smarty(); - $this->smarty->setCompileDir(config('ytake-laravel-smarty.compile_path')); - $this->smarty->setConfigDir(array_get(config('ytake-laravel-smarty'), 'config_paths')); - $this->smarty->setCacheDir(config('ytake-laravel-smarty.cache_path')); + app('smarty.view')->setCompileDir(config('ytake-laravel-smarty.compile_path')); + app('smarty.view')->setConfigDir(array_get(config('ytake-laravel-smarty'), 'config_paths')); + app('smarty.view')->setCacheDir(config('ytake-laravel-smarty.cache_path')); foreach (array_get(config('ytake-laravel-smarty'), 'plugins_paths', []) as $plugins) { - $this->smarty->addPluginsDir($plugins); + app('smarty.view')->addPluginsDir($plugins); } - $this->smarty->error_reporting = E_ALL & ~E_NOTICE; + app('smarty.view')->error_reporting = E_ALL & ~E_NOTICE; - $this->smarty->assign('serverroot', url('/')); + app('smarty.view')->assign('serverroot', url('/')); $this->page = request()->input('page') ?? 'content'; @@ -141,17 +140,17 @@ class BasePage } else { $this->theme = $this->getSettingValue('site.main.style'); - $this->smarty->assign('isadmin', 'false'); - $this->smarty->assign('ismod', 'false'); - $this->smarty->assign('loggedin', 'false'); + app('smarty.view')->assign('isadmin', 'false'); + app('smarty.view')->assign('ismod', 'false'); + app('smarty.view')->assign('loggedin', 'false'); } if ($this->theme === 'None') { $this->theme = Settings::settingValue('site.main.style'); } - $this->smarty->assign('theme', $this->theme); - $this->smarty->assign('site', $this->settings); - $this->smarty->assign('page', $this); + app('smarty.view')->assign('theme', $this->theme); + app('smarty.view')->assign('site', $this->settings); + app('smarty.view')->assign('page', $this); } /** @@ -165,26 +164,6 @@ class BasePage $this->show503(); } - /** - * Inject content into the html head. - * - * @param $headcontent - */ - public function addToHead($headcontent): void - { - $this->head = $this->head."\n".$headcontent; - } - - /** - * Inject js/attributes into the html body tag. - * - * @param $attr - */ - public function addToBody($attr): void - { - $this->body = $this->body.' '.$attr; - } - /** * @return bool */ @@ -277,7 +256,7 @@ class BasePage public function render() { - $this->smarty->display($this->page_template); + app('smarty.view')->display($this->page_template); } /** @@ -303,73 +282,39 @@ class BasePage User::updateSiteAccessed($this->userdata['id']); } - $this->smarty->assign('userdata', $this->userdata); - $this->smarty->assign('loggedin', 'true'); + app('smarty.view')->assign('userdata', $this->userdata); + app('smarty.view')->assign('loggedin', 'true'); if ($this->userdata['nzbvortex_api_key'] !== '' && $this->userdata['nzbvortex_server_url'] !== '') { - $this->smarty->assign('weHasVortex', true); + app('smarty.view')->assign('weHasVortex', true); } else { - $this->smarty->assign('weHasVortex', false); + app('smarty.view')->assign('weHasVortex', false); } $sab = new SABnzbd($this); - $this->smarty->assign('sabintegrated', $sab->integratedBool); + app('smarty.view')->assign('sabintegrated', $sab->integratedBool); if ($sab->integratedBool !== false && $sab->url !== '' && $sab->apikey !== '') { - $this->smarty->assign('sabapikeytype', $sab->apikeytype); + app('smarty.view')->assign('sabapikeytype', $sab->apikeytype); } switch ((int) $this->userdata['user_roles_id']) { case User::ROLE_ADMIN: - $this->smarty->assign('isadmin', 'true'); + app('smarty.view')->assign('isadmin', 'true'); break; case User::ROLE_MODERATOR: - $this->smarty->assign('ismod', 'true'); + app('smarty.view')->assign('ismod', 'true'); } } - /** - * Allows to fetch a value from the settings table. - * - * This method is deprecated, as the column it uses to select the data is due to be removed - * from the table *soon*. - * - * @param $setting - * - * @return array|bool|mixed|null|string - * @throws \Exception - */ - public function getSetting($setting) - { - if (strpos($setting, '.') === false) { - trigger_error('You should update your template to use the newer method "$page->getSettingValue()"" of fetching values from the "settings" table! This method *will* be removed in a future version.', E_USER_WARNING); - } else { - return $this->getSettingValue($setting); - } - - return $this->settings->$setting; - } - - /** - * @param $setting - * - * @return null|string - * @throws \Exception - */ - public function getSettingValue($setting): ?string - { - return Settings::settingValue($setting); - } - /** * Setup user preferences. * * * @throws \Exception - * @throws \SmartyException */ public function setUserPrefs() { // Tell Smarty which directories to use for templates - $this->smarty->setTemplateDir([ + app('smarty.view')->setTemplateDir([ 'user' => config('ytake-laravel-smarty.template_path').DIRECTORY_SEPARATOR.$this->theme, 'shared' => config('ytake-laravel-smarty.template_path').'/shared', 'default' => config('ytake-laravel-smarty.template_path').'/Gentele', @@ -381,16 +326,16 @@ class BasePage } $content = new Contents(); - $this->smarty->assign('menulist', Menu::getMenu($role, $this->serverurl)); - $this->smarty->assign('usefulcontentlist', $content->getForMenuByTypeAndRole(Contents::TYPEUSEFUL, $role)); - $this->smarty->assign('articlecontentlist', $content->getForMenuByTypeAndRole(Contents::TYPEARTICLE, $role)); + app('smarty.view')->assign('menulist', Menu::getMenu($role, $this->serverurl)); + app('smarty.view')->assign('usefulcontentlist', $content->getForMenuByTypeAndRole(Contents::TYPEUSEFUL, $role)); + app('smarty.view')->assign('articlecontentlist', $content->getForMenuByTypeAndRole(Contents::TYPEARTICLE, $role)); if ($this->userdata !== null) { - $this->smarty->assign('recentforumpostslist', Forumpost::getPosts(Settings::settingValue('..showrecentforumposts'))); + app('smarty.view')->assign('recentforumpostslist', Forumpost::getPosts(Settings::settingValue('..showrecentforumposts'))); } - $this->smarty->assign('main_menu', $this->smarty->fetch('mainmenu.tpl')); - $this->smarty->assign('useful_menu', $this->smarty->fetch('usefullinksmenu.tpl')); - $this->smarty->assign('article_menu', $this->smarty->fetch('articlesmenu.tpl')); + app('smarty.view')->assign('main_menu', app('smarty.view')->fetch('mainmenu.tpl')); + app('smarty.view')->assign('useful_menu', app('smarty.view')->fetch('usefullinksmenu.tpl')); + app('smarty.view')->assign('article_menu', app('smarty.view')->fetch('articlesmenu.tpl')); if (! empty($this->userdata)) { $parentcatlist = Category::getForMenu($this->userdata['categoryexclusions'], $this->userdata['rolecategoryexclusions']); @@ -398,27 +343,27 @@ class BasePage $parentcatlist = Category::getForMenu(); } - $this->smarty->assign('parentcatlist', $parentcatlist); - $this->smarty->assign('catClass', Category::class); + app('smarty.view')->assign('parentcatlist', $parentcatlist); + app('smarty.view')->assign('catClass', Category::class); $searchStr = ''; if ($this->page === 'search' && request()->has('id')) { $searchStr = request()->input('id'); } - $this->smarty->assign('header_menu_search', $searchStr); + app('smarty.view')->assign('header_menu_search', $searchStr); if (request()->has('t')) { - $this->smarty->assign('header_menu_cat', request()->input('t')); + app('smarty.view')->assign('header_menu_cat', request()->input('t')); } else { - $this->smarty->assign('header_menu_cat', ''); + app('smarty.view')->assign('header_menu_cat', ''); } - $header_menu = $this->smarty->fetch('headermenu.tpl'); - $this->smarty->assign('header_menu', $header_menu); + $header_menu = app('smarty.view')->fetch('headermenu.tpl'); + app('smarty.view')->assign('header_menu', $header_menu); } public function setAdminPrefs() { // Tell Smarty which directories to use for templates - $this->smarty->setTemplateDir( + app('smarty.view')->setTemplateDir( [ 'admin' => config('ytake-laravel-smarty.template_path').'/admin', 'shared' => config('ytake-laravel-smarty.template_path').'/shared', @@ -426,7 +371,7 @@ class BasePage ] ); - $this->smarty->assign('catClass', Category::class); + app('smarty.view')->assign('catClass', Category::class); } /** @@ -434,7 +379,7 @@ class BasePage */ public function pagerender(): void { - $this->smarty->assign('page', $this); + app('smarty.view')->assign('page', $this); $this->page_template = 'basepage.tpl'; $this->render(); @@ -447,10 +392,10 @@ class BasePage */ public function adminrender(): void { - $this->smarty->assign('page', $this); + app('smarty.view')->assign('page', $this); - $admin_menu = $this->smarty->fetch('adminmenu.tpl'); - $this->smarty->assign('admin_menu', $admin_menu); + $admin_menu = app('smarty.view')->fetch('adminmenu.tpl'); + app('smarty.view')->assign('admin_menu', $admin_menu); $this->page_template = 'baseadminpage.tpl'; diff --git a/Changelog b/Changelog index fde28f02d..066e3415c 100755 --- a/Changelog +++ b/Changelog @@ -1,3 +1,5 @@ +2018-03-29 DariusIII + * Chg: Remove login/register pages, use Login/Register controllers completely 2018-03-28 DariusIII * Chg: Update laravel/framework to version 5.6.14 * Chg: Change login/register pages diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index ccbe7c441..a35b31dbd 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\Auth; +use App\Models\Settings; use Illuminate\Http\Request; use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Auth; @@ -65,10 +66,35 @@ class LoginController extends Controller return redirect()->intended($this->redirectPath()); } + app('smarty.view')->assign('error', 'These credentials do not match our records.'); return redirect()->back() ->withInput() ->withErrors([ 'login' => 'These credentials do not match our records.', ]); } + + /** + * @throws \Exception + */ + public function showLoginForm() + { + $theme = Settings::settingValue('site.main.style'); + app('smarty.view')->assign(['error' => '', 'username' => '', 'rememberme' => '']); + + $meta_title = 'Login'; + $meta_keywords = 'Login'; + $meta_description = 'Login'; + $content = app('smarty.view')->fetch($theme.'/login.tpl'); + app('smarty.view')->assign( + [ + 'error' => 'These credentials do not match our records.', + 'content' => $content, + 'meta_title' => $meta_title, + 'meta_keywords' => $meta_keywords, + 'meta_description' => $meta_description, + ] + ); + app('smarty.view')->display($theme.'/basepage.tpl'); + } } diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index 76788334a..5241ac939 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -85,7 +85,7 @@ class RegisterController extends Controller public function register(Request $request) { - $userName = $password = $confirmPassword = $email = $inviteCode = $inviteCodeQuery = ''; + $error = $userName = $password = $confirmPassword = $email = $inviteCode = $inviteCodeQuery = ''; $showRegister = 1; if ((int) Settings::settingValue('..registerstatus') === Settings::REGISTER_STATUS_CLOSED) { @@ -118,41 +118,41 @@ class RegisterController extends Controller if ((int) Settings::settingValue('..registerstatus') === Settings::REGISTER_STATUS_INVITE) { if ($inviteCode === '') { - echo 'Sorry, the invite code is old or has been used.'; + $error = 'Sorry, the invite code is old or has been used.'; break; } $invitedBy = User::checkAndUseInvite($inviteCode); if ($invitedBy < 0) { - echo 'Sorry, the invite code is old or has been used.'; + $error = 'Sorry, the invite code is old or has been used.'; break; } } if (! User::isValidUsername($userName)) { - echo 'Your username must be at least five characters.'; + $error = 'Your username must be at least five characters.'; break; } if (! User::isValidPassword($password)) { - echo 'Your password must be longer than eight characters, have at least 1 number, at least 1 capital and at least one lowercase letter'; + $error = 'Your password must be longer than eight characters, have at least 1 number, at least 1 capital and at least one lowercase letter'; break; } if (! User::isValidEmail($email)) { - echo 'Your email is not a valid format.'; + $error = 'Your email is not a valid format.'; break; } $res = User::getByUsername($userName); if ($res) { - echo 'Sorry, the username is already taken.'; + $error = 'Sorry, the username is already taken.'; break; } $res = User::getByEmail($email); if ($res) { - echo 'Sorry, the email is already in use.'; + $error = 'Sorry, the email is already in use.'; break; } @@ -181,7 +181,7 @@ class RegisterController extends Controller // See if it is a valid invite. $invite = Invitation::getInvite($inviteCode); if (! $invite) { - echo sprintf('Bad or invite code older than %d days.', Invitation::DEFAULT_INVITE_EXPIRY_DAYS); + $error = sprintf('Bad or invite code older than %d days.', Invitation::DEFAULT_INVITE_EXPIRY_DAYS); $showRegister = 0; } else { $inviteCode = $invite['guid']; @@ -191,5 +191,40 @@ class RegisterController extends Controller } } } + app('smarty.view')->assign( + [ + 'username' => Utility::htmlfmt($userName), + 'password' => Utility::htmlfmt($password), + 'confirmpassword' => Utility::htmlfmt($confirmPassword), + 'email' => Utility::htmlfmt($email), + 'invitecode' => Utility::htmlfmt($inviteCode), + 'invite_code_query' => Utility::htmlfmt($inviteCodeQuery), + 'showregister' => $showRegister, + 'error' => $error, + ] + ); + } + + /** + * @throws \Exception + */ + public function showRegistrationForm() + { + $theme = Settings::settingValue('site.main.style'); + + $meta_title = 'Register'; + $meta_keywords = 'register,signup,registration'; + $meta_description = 'Register'; + + $content = app('smarty.view')->fetch($theme.'/register.tpl'); + app('smarty.view')->assign( + [ + 'content' => $content, + 'meta_title' => $meta_title, + 'meta_keywords' => $meta_keywords, + 'meta_description' => $meta_description, + ] + ); + app('smarty.view')->display($theme.'/basepage.tpl'); } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 8bb91f05f..baec82066 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -13,7 +13,8 @@ class AppServiceProvider extends ServiceProvider */ public function boot() { - // + $smarty = app('smarty.view'); + view()->share('smarty', $smarty); } /** diff --git a/public/index.php b/public/index.php index 3439e63fd..149d43326 100644 --- a/public/index.php +++ b/public/index.php @@ -56,7 +56,6 @@ switch ($page->page) { case 'profileedit': case 'profile_delete': case 'queue': - case 'register': case 'sabqueuedata': case 'search': case 'sendtocouch': @@ -70,7 +69,6 @@ switch ($page->page) { case 'api': case 'failed': case 'getnzb': - case 'login': case 'rss': include NN_WWW.'pages/'.$page->page.'.php'; break; diff --git a/public/pages/login.php b/public/pages/login.php deleted file mode 100644 index 896818d0e..000000000 --- a/public/pages/login.php +++ /dev/null @@ -1,9 +0,0 @@ -smarty->assign(['error' => '', 'username' => '', 'rememberme' => '']); - -$page->meta_title = 'Login'; -$page->meta_keywords = 'Login'; -$page->meta_description = 'Login'; -$page->content = $page->smarty->fetch('login.tpl'); -$page->pagerender(); diff --git a/public/pages/register.php b/public/pages/register.php deleted file mode 100644 index d78f0e7ec..000000000 --- a/public/pages/register.php +++ /dev/null @@ -1,30 +0,0 @@ -smarty->assign( - [ - 'username' => Utility::htmlfmt($userName), - 'password' => Utility::htmlfmt($password), - 'confirmpassword' => Utility::htmlfmt($confirmPassword), - 'email' => Utility::htmlfmt($email), - 'invitecode' => Utility::htmlfmt($inviteCode), - 'invite_code_query' => Utility::htmlfmt($inviteCodeQuery), - 'showregister' => $showRegister, - 'error' => $error, - ] -); -$page->meta_title = 'Register'; -$page->meta_keywords = 'register,signup,registration'; -$page->meta_description = 'Register'; - -$page->content = $page->smarty->fetch('register.tpl'); -$page->pagerender(); diff --git a/resources/views/themes/Charisma/basepage.tpl b/resources/views/themes/Charisma/basepage.tpl index 77431157c..678207898 100755 --- a/resources/views/themes/Charisma/basepage.tpl +++ b/resources/views/themes/Charisma/basepage.tpl @@ -24,7 +24,7 @@ === --> -
- {$page->smarty->fetch('captcha.tpl')} + {NoCaptcha::display()}{NoCaptcha::renderJs()}
diff --git a/resources/views/themes/Charisma/login.tpl b/resources/views/themes/Charisma/login.tpl index 0343465c5..02ecf74c7 100755 --- a/resources/views/themes/Charisma/login.tpl +++ b/resources/views/themes/Charisma/login.tpl @@ -67,7 +67,7 @@
- {$page->smarty->fetch('captcha.tpl')} + {NoCaptcha::display()}{NoCaptcha::renderJs()}
diff --git a/resources/views/themes/Charisma/profileedit.tpl b/resources/views/themes/Charisma/profileedit.tpl index c03dee950..f45024ab5 100755 --- a/resources/views/themes/Charisma/profileedit.tpl +++ b/resources/views/themes/Charisma/profileedit.tpl @@ -146,7 +146,7 @@| - {$page->smarty->fetch('captcha.tpl')} + {NoCaptcha::display()}{NoCaptcha::renderJs()} |
The following queue is pulled from
{$serverURL|escape:"htmlall"}.
- {if $page->getSettingValue('apps.sabnzbplus.integrationtype') == 2 || $user.queuetype == 2}Edit your queue settings in
+ {if {{App\Models\Settings::settingValue('apps.sabnzbplus.integrationtype')}} == 2 || $user.queuetype == 2}Edit your queue settings in
your profile
.{/if}
| - {if $page->getSettingValue('site.main.userselstyle') == 1} + {if {{App\Models\Settings::settingValue('site.main.userselstyle')}} == 1} {html_options id="style" name='style' values=$themelist output=$themelist selected=$user.style} {/if} | @@ -171,7 +171,7 @@ function.