[CONTROLLER][ROUTES] Refactor controllers to use the new base class and remove controller from the class name

This commit is contained in:
Hugo Sales 2020-07-23 14:08:31 +00:00 committed by Hugo Sales
parent 2796ac5228
commit 56f74fffe8
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
4 changed files with 27 additions and 31 deletions

View File

@ -42,7 +42,7 @@ use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
class AdminConfigController extends Controller class AdminPanel extends Controller
{ {
public function handle(Request $request) public function handle(Request $request)
{ {
@ -55,9 +55,11 @@ class AdminConfigController extends Controller
} }
} }
$form = Form::create([[_m('Setting'), ChoiceType::class, ['choices' => $options]], $form = Form::create([
[_m('Setting'), ChoiceType::class, ['choices' => $options]],
[_m('Value'), TextType::class], [_m('Value'), TextType::class],
['save', SubmitType::class, ['label' => _m('Set site setting')]], ]); ['save', SubmitType::class, ['label' => _m('Set site setting')]],
]);
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isSubmitted()) { if ($form->isSubmitted()) {
@ -66,17 +68,19 @@ class AdminConfigController extends Controller
list($section, $setting) = explode(':', $data[_m('Setting')]); list($section, $setting) = explode(':', $data[_m('Setting')]);
$value = $data[_m('Value')]; $value = $data[_m('Value')];
$default = $defaults[$section][$setting]; $default = $defaults[$section][$setting];
// Sanity check
if (gettype($default) === gettype($value)) { if (gettype($default) === gettype($value)) {
$conf = DB::find('config', ['section' => $section, 'setting' => $setting]); $conf = DB::find('config', ['section' => $section, 'setting' => $setting]);
$old_value = $conf->getValue(); $old_value = unserialize($conf->getValue());
$conf->setValue(serialize($value)); $conf->setValue(serialize($value));
DB::flush(); DB::flush();
} return [
return $this->render('config/admin.html.twig', [ '_template' => 'config/admin.html.twig',
'form' => $form->createView(), 'form' => $form->createView(),
'old_value' => unserialize($old_value), 'old_value' => $old_value,
'default' => $default, 'default' => $default,
]); ];
}
} else { } else {
// TODO Display error // TODO Display error
} }

View File

@ -2,11 +2,11 @@
namespace App\Controller; namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use App\Core\Controller;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class SecurityController extends AbstractController class Security extends Controller
{ {
public function login(AuthenticationUtils $authenticationUtils): Response public function login(AuthenticationUtils $authenticationUtils): Response
{ {
@ -17,9 +17,9 @@ class SecurityController extends AbstractController
// get the login error if there is one // get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError(); $error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user // last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername(); $last_username = $authenticationUtils->getLastUsername();
return $this->render('security/login.html.twig', ['last_username' => $lastUsername, 'error' => $error]); return ['_template' => 'security/login.html.twig', 'last_username' => $last_username, 'error' => $error];
} }
public function logout() public function logout()

View File

@ -31,8 +31,6 @@
namespace App\Controller; namespace App\Controller;
// use App\Core\Event;
// use App\Util\Common;
use App\Core\DB\DB; use App\Core\DB\DB;
use App\Core\Form; use App\Core\Form;
use function App\Core\I18n\_m; use function App\Core\I18n\_m;
@ -72,9 +70,7 @@ class UserPanel extends AbstractController
} }
} }
return $this->render('settings/profile.html.twig', [ return ['_template' => 'settings/profile.html.twig', 'prof' => $prof->createView()];
'prof' => $prof->createView(),
]);
} }
public function account(Request $request) public function account(Request $request)
@ -89,9 +85,7 @@ class UserPanel extends AbstractController
[_m('emailnotifyfav'), CheckboxType::class, ['help' => 'Send me email when someone adds my notice as a favorite.', 'label_format' => 'Notify favorites']], [_m('emailnotifyfav'), CheckboxType::class, ['help' => 'Send me email when someone adds my notice as a favorite.', 'label_format' => 'Notify favorites']],
['save', SubmitType::class, ['label' => _m('Save')]], ]); ['save', SubmitType::class, ['label' => _m('Save')]], ]);
return $this->render('settings/account.html.twig', [ return ['_template' => 'settings/account.html.twig', 'acc' => $acc->createView()];
'acc' => $acc->createView(),
]);
} }
public function avatar(Request $request) public function avatar(Request $request)
@ -100,9 +94,7 @@ class UserPanel extends AbstractController
[_m('avatar'), FileType::class, ['help' => 'You can upload your personal avatar. The maximum file size is 64MB.', 'label_format' => 'Avatar']], [_m('avatar'), FileType::class, ['help' => 'You can upload your personal avatar. The maximum file size is 64MB.', 'label_format' => 'Avatar']],
['save', SubmitType::class, ['label' => _m('Submit')]], ]); ['save', SubmitType::class, ['label' => _m('Submit')]], ]);
return $this->render('settings/avatar.html.twig', [ return ['_template' => 'settings/avatar.html.twig', 'avatar' => $avatar->createView()];
'avatar' => $avatar->createView(),
]);
} }
public function misc(Request $request) public function misc(Request $request)
@ -114,8 +106,6 @@ class UserPanel extends AbstractController
[_m('posts_by_followed'), CheckboxType::class, ['help' => 'Send me notices.', 'label_format' => 'Notices']], [_m('posts_by_followed'), CheckboxType::class, ['help' => 'Send me notices.', 'label_format' => 'Notices']],
['save', SubmitType::class, ['label' => _m('Save')]], ]); ['save', SubmitType::class, ['label' => _m('Save')]], ]);
return $this->render('settings/misc.html.twig', [ return ['_template' => 'settings/misc.html.twig', 'misc' => $misc->createView()];
'misc' => $misc->createView(),
]);
} }
} }

View File

@ -1,6 +1,7 @@
<?php <?php
// {{{ License // {{{ License
// This file is part of GNU social - https://www.gnu.org/software/social // This file is part of GNU social - https://www.gnu.org/software/social
// //
// GNU social is free software: you can redistribute it and/or modify // GNU social is free software: you can redistribute it and/or modify
@ -15,6 +16,7 @@
// //
// You should have received a copy of the GNU Affero General Public License // You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
// }}} // }}}
/** /**
@ -40,10 +42,10 @@ abstract class Main
public static function load(RouteLoader $r): void public static function load(RouteLoader $r): void
{ {
$r->connect('main_all', '/main/all', C\NetworkPublic::class); $r->connect('main_all', '/main/all', C\NetworkPublic::class);
$r->connect('admin_config', '/admin/config', C\AdminConfigController::class); $r->connect('admin_config', '/admin/config', C\AdminPanel::class);
$r->connect('login', '/login', [C\SecurityController::class, 'login']); $r->connect('login', '/login', [C\Security::class, 'login']);
$r->connect('logout', '/logout', [C\SecurityController::class, 'logout']); $r->connect('logout', '/logout', [C\Security::class, 'logout']);
// FAQ static pages // FAQ static pages
foreach (['faq', 'contact', 'tags', 'groups', 'openid'] as $s) { foreach (['faq', 'contact', 'tags', 'groups', 'openid'] as $s) {