![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/mautic.corals.io/app/bundles/UserBundle/Controller/ |
<?php namespace Mautic\UserBundle\Controller; use Mautic\CoreBundle\Controller\CommonController; use Mautic\CoreBundle\Service\FlashBag; use Mautic\PluginBundle\Helper\IntegrationHelper; use Mautic\UserBundle\Exception\WeakPasswordException; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; use Symfony\Component\Security\Core\Exception; use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; use Symfony\Contracts\Translation\TranslatorInterface; class SecurityController extends CommonController implements EventSubscriberInterface { public function onRequest(RequestEvent $event): void { $controller = $event->getRequest()->attributes->get('_controller'); \assert(is_string($controller)); if (!str_contains($controller, self::class)) { return; } $authChecker = $this->get('security.authorization_checker'); \assert($authChecker instanceof AuthorizationCheckerInterface); // redirect user if they are already authenticated if ($authChecker->isGranted('IS_AUTHENTICATED_FULLY') || $authChecker->isGranted('IS_AUTHENTICATED_REMEMBERED') ) { $redirectUrl = $this->generateUrl('mautic_dashboard_index'); $event->setResponse(new RedirectResponse($redirectUrl)); } } /** * Generates login form and processes login. * * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response */ public function loginAction(Request $request, AuthenticationUtils $authenticationUtils, IntegrationHelper $integrationHelper, TranslatorInterface $translator): \Symfony\Component\HttpFoundation\Response { $error = $authenticationUtils->getLastAuthenticationError(); if (null !== $error) { if ($error instanceof WeakPasswordException) { $this->addFlash(FlashBag::LEVEL_ERROR, $translator->trans('mautic.user.auth.error.weakpassword', [], 'flashes')); return $this->forward('Mautic\UserBundle\Controller\PublicController::passwordResetAction'); } elseif ($error instanceof Exception\BadCredentialsException) { $msg = 'mautic.user.auth.error.invalidlogin'; } elseif ($error instanceof Exception\DisabledException) { $msg = 'mautic.user.auth.error.disabledaccount'; } else { $msg = $error->getMessage(); } $this->addFlashMessage($msg, [], FlashBag::LEVEL_ERROR, null, false); } $request->query->set('tmpl', 'login'); // Get a list of SSO integrations $integrations = $integrationHelper->getIntegrationObjects(null, ['sso_service'], true, null, true); return $this->delegateView([ 'viewParameters' => [ 'last_username' => $authenticationUtils->getLastUsername(), 'integrations' => $integrations, ], 'contentTemplate' => '@MauticUser/Security/login.html.twig', 'passthroughVars' => [ 'route' => $this->generateUrl('login'), 'mauticContent' => 'user', 'sessionExpired' => true, ], ]); } /** * Do nothing. */ public function loginCheckAction(): void { } /** * The plugin should be handling this in it's listener. */ public function ssoLoginAction($integration): RedirectResponse { return new RedirectResponse($this->generateUrl('login')); } /** * The plugin should be handling this in it's listener. */ public function ssoLoginCheckAction($integration): RedirectResponse { // The plugin should be handling this in it's listener return new RedirectResponse($this->generateUrl('login')); } /** * @return array<string, string> */ public static function getSubscribedEvents(): array { return [ KernelEvents::REQUEST => 'onRequest', ]; } }