1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-08-01 17:38:38 +00:00

Use FQCN instead of service alias

This commit is contained in:
Yassine Guedidi 2022-08-28 02:01:46 +02:00
parent 156158673f
commit eb43c78720
62 changed files with 579 additions and 404 deletions

View file

@ -2,9 +2,14 @@
namespace Wallabag\CoreBundle\Controller;
use Craue\ConfigBundle\Util\Config;
use Doctrine\Persistence\ManagerRegistry;
use FOS\UserBundle\Model\UserManagerInterface;
use JMS\Serializer\SerializationContext;
use JMS\Serializer\SerializerBuilder;
use Liip\ThemeBundle\ActiveTheme;
use PragmaRX\Recovery\Recovery as BackupCodes;
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\Google\GoogleAuthenticatorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
@ -12,7 +17,9 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Validator\Constraints\Locale as LocaleConstraint;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Wallabag\AnnotationBundle\Entity\Annotation;
use Wallabag\CoreBundle\Entity\Config as ConfigEntity;
use Wallabag\CoreBundle\Entity\IgnoreOriginUserRule;
@ -39,7 +46,7 @@ class ConfigController extends Controller
{
$em = $this->getDoctrine()->getManager();
$config = $this->getConfig();
$userManager = $this->container->get('fos_user.user_manager');
$userManager = $this->container->get(UserManagerInterface::class);
$user = $this->getUser();
// handle basic config detail (this form is defined as a service)
@ -63,7 +70,7 @@ class ConfigController extends Controller
$request->getSession()->set('_locale', $config->getLanguage());
// switch active theme
$activeTheme = $this->get('liip_theme.active_theme');
$activeTheme = $this->get(ActiveTheme::class);
$activeTheme->setName($config->getTheme());
$this->addFlash(
@ -79,7 +86,7 @@ class ConfigController extends Controller
$pwdForm->handleRequest($request);
if ($pwdForm->isSubmitted() && $pwdForm->isValid()) {
if ($this->get('craue_config')->get('demo_mode_enabled') && $this->get('craue_config')->get('demo_mode_username') === $user->getUsername()) {
if ($this->get(Config::class)->get('demo_mode_enabled') && $this->get(Config::class)->get('demo_mode_username') === $user->getUsername()) {
$message = 'flashes.config.notice.password_not_updated_demo';
} else {
$message = 'flashes.config.notice.password_updated';
@ -258,7 +265,7 @@ class ConfigController extends Controller
$user = $this->getUser();
$user->setEmailTwoFactor(false);
$this->container->get('fos_user.user_manager')->updateUser($user, true);
$this->container->get(UserManagerInterface::class)->updateUser($user, true);
$this->addFlash(
'notice',
@ -285,7 +292,7 @@ class ConfigController extends Controller
$user->setBackupCodes(null);
$user->setEmailTwoFactor(true);
$this->container->get('fos_user.user_manager')->updateUser($user, true);
$this->container->get(UserManagerInterface::class)->updateUser($user, true);
$this->addFlash(
'notice',
@ -311,7 +318,7 @@ class ConfigController extends Controller
$user->setGoogleAuthenticatorSecret('');
$user->setBackupCodes(null);
$this->container->get('fos_user.user_manager')->updateUser($user, true);
$this->container->get(UserManagerInterface::class)->updateUser($user, true);
$this->addFlash(
'notice',
@ -333,7 +340,7 @@ class ConfigController extends Controller
}
$user = $this->getUser();
$secret = $this->get('scheb_two_factor.security.google_authenticator')->generateSecret();
$secret = $this->get(GoogleAuthenticatorInterface::class)->generateSecret();
$user->setGoogleAuthenticatorSecret($secret);
$user->setEmailTwoFactor(false);
@ -348,7 +355,7 @@ class ConfigController extends Controller
$user->setBackupCodes($backupCodesHashed);
$this->container->get('fos_user.user_manager')->updateUser($user, true);
$this->container->get(UserManagerInterface::class)->updateUser($user, true);
$this->addFlash(
'notice',
@ -357,7 +364,7 @@ class ConfigController extends Controller
return $this->render('@WallabagCore/Config/otp_app.html.twig', [
'backupCodes' => $backupCodes,
'qr_code' => $this->get('scheb_two_factor.security.google_authenticator')->getQRContent($user),
'qr_code' => $this->get(GoogleAuthenticatorInterface::class)->getQRContent($user),
'secret' => $secret,
]);
}
@ -377,7 +384,7 @@ class ConfigController extends Controller
$user->setGoogleAuthenticatorSecret(null);
$user->setBackupCodes(null);
$this->container->get('fos_user.user_manager')->updateUser($user, true);
$this->container->get(UserManagerInterface::class)->updateUser($user, true);
return $this->redirect($this->generateUrl('config') . '#set3');
}
@ -389,7 +396,7 @@ class ConfigController extends Controller
*/
public function otpAppCheckAction(Request $request)
{
$isValid = $this->get('scheb_two_factor.security.google_authenticator')->checkCode(
$isValid = $this->get(GoogleAuthenticatorInterface::class)->checkCode(
$this->getUser(),
$request->get('_auth_code')
);
@ -558,7 +565,7 @@ class ConfigController extends Controller
case 'entries':
// SQLite doesn't care about cascading remove, so we need to manually remove associated stuff
// otherwise they won't be removed ...
if ($this->get('doctrine')->getConnection()->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) {
if ($this->get(ManagerRegistry::class)->getConnection()->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) {
$this->getDoctrine()->getRepository(Annotation::class)->removeAllByUserId($this->getUser()->getId());
}
@ -568,7 +575,7 @@ class ConfigController extends Controller
$this->get(EntryRepository::class)->removeAllByUserId($this->getUser()->getId());
break;
case 'archived':
if ($this->get('doctrine')->getConnection()->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) {
if ($this->get(ManagerRegistry::class)->getConnection()->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) {
$this->removeAnnotationsForArchivedByUserId($this->getUser()->getId());
}
@ -608,10 +615,10 @@ class ConfigController extends Controller
$user = $this->getUser();
// logout current user
$this->get('security.token_storage')->setToken(null);
$this->get(TokenStorageInterface::class)->setToken(null);
$request->getSession()->invalidate();
$em = $this->get('fos_user.user_manager');
$em = $this->get(UserManagerInterface::class);
$em->deleteUser($user);
return $this->redirect($this->generateUrl('fos_user_security_login'));
@ -647,7 +654,7 @@ class ConfigController extends Controller
*/
public function setLocaleAction(Request $request, $language = null)
{
$errors = $this->get('validator')->validate($language, (new LocaleConstraint()));
$errors = $this->get(ValidatorInterface::class)->validate($language, (new LocaleConstraint()));
if (0 === \count($errors)) {
$request->getSession()->set('_locale', $language);