[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
No known key found for this signature in database
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\HttpFoundation\Request;
class AdminConfigController extends Controller
class AdminPanel extends Controller
{
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],
['save', SubmitType::class, ['label' => _m('Set site setting')]], ]);
['save', SubmitType::class, ['label' => _m('Set site setting')]],
]);
$form->handleRequest($request);
if ($form->isSubmitted()) {
@ -66,17 +68,19 @@ class AdminConfigController extends Controller
list($section, $setting) = explode(':', $data[_m('Setting')]);
$value = $data[_m('Value')];
$default = $defaults[$section][$setting];
// Sanity check
if (gettype($default) === gettype($value)) {
$conf = DB::find('config', ['section' => $section, 'setting' => $setting]);
$old_value = $conf->getValue();
$old_value = unserialize($conf->getValue());
$conf->setValue(serialize($value));
DB::flush();
return [
'_template' => 'config/admin.html.twig',
'form' => $form->createView(),
'old_value' => $old_value,
'default' => $default,
];
}
return $this->render('config/admin.html.twig', [
'form' => $form->createView(),
'old_value' => unserialize($old_value),
'default' => $default,
]);
} else {
// TODO Display error
}

View File

@ -2,11 +2,11 @@
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use App\Core\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class SecurityController extends AbstractController
class Security extends Controller
{
public function login(AuthenticationUtils $authenticationUtils): Response
{
@ -17,9 +17,9 @@ class SecurityController extends AbstractController
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// 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()

View File

@ -31,8 +31,6 @@
namespace App\Controller;
// use App\Core\Event;
// use App\Util\Common;
use App\Core\DB\DB;
use App\Core\Form;
use function App\Core\I18n\_m;
@ -72,9 +70,7 @@ class UserPanel extends AbstractController
}
}
return $this->render('settings/profile.html.twig', [
'prof' => $prof->createView(),
]);
return ['_template' => 'settings/profile.html.twig', 'prof' => $prof->createView()];
}
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']],
['save', SubmitType::class, ['label' => _m('Save')]], ]);
return $this->render('settings/account.html.twig', [
'acc' => $acc->createView(),
]);
return ['_template' => 'settings/account.html.twig', 'acc' => $acc->createView()];
}
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']],
['save', SubmitType::class, ['label' => _m('Submit')]], ]);
return $this->render('settings/avatar.html.twig', [
'avatar' => $avatar->createView(),
]);
return ['_template' => 'settings/avatar.html.twig', 'avatar' => $avatar->createView()];
}
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']],
['save', SubmitType::class, ['label' => _m('Save')]], ]);
return $this->render('settings/misc.html.twig', [
'misc' => $misc->createView(),
]);
return ['_template' => 'settings/misc.html.twig', 'misc' => $misc->createView()];
}
}
}

View File

@ -1,6 +1,7 @@
<?php
// {{{ License
// 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
@ -15,6 +16,7 @@
//
// 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/>.
// }}}
/**
@ -40,10 +42,10 @@ abstract class Main
public static function load(RouteLoader $r): void
{
$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('logout', '/logout', [C\SecurityController::class, 'logout']);
$r->connect('login', '/login', [C\Security::class, 'login']);
$r->connect('logout', '/logout', [C\Security::class, 'logout']);
// FAQ static pages
foreach (['faq', 'contact', 'tags', 'groups', 'openid'] as $s) {