Fixed code style.

This commit is contained in:
Jan Böhmer 2020-01-04 20:24:09 +01:00
parent 1aed1d1d26
commit 9a7223a301
142 changed files with 534 additions and 716 deletions

View file

@ -21,7 +21,6 @@
namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Mailer\Event\MessageEvent;
use Symfony\Component\Mime\Address;
@ -34,7 +33,7 @@ class MailFromListener implements EventSubscriberInterface
public function __construct(string $email, string $name)
{
$this->email = $email;
$this->email = $email;
$this->name = $name;
}
@ -55,4 +54,4 @@ class MailFromListener implements EventSubscriberInterface
MessageEvent::class => ['onMessage'],
];
}
}
}

View file

@ -21,7 +21,6 @@
namespace App\EventSubscriber;
use App\Entity\UserSystem\User;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
@ -34,18 +33,16 @@ use Symfony\Component\Security\Http\HttpUtils;
* This event subscriber redirects a user to its settings page, when it needs to change its password or is enforced
* to setup a 2FA method (enforcement can be set per group).
* In this cases the user is unable to access sites other than the whitelisted (see ALLOWED_ROUTES).
* @package App\EventSubscriber
*/
class PasswordChangeNeededSubscriber implements EventSubscriberInterface
{
protected $security;
protected $flashBag;
protected $httpUtils;
/**
* @var string[] The routes the user is allowed to access without being redirected.
* This should be only routes related to login/logout and user settings
* This should be only routes related to login/logout and user settings
*/
public const ALLOWED_ROUTES = [
'2fa_login',
@ -69,17 +66,16 @@ class PasswordChangeNeededSubscriber implements EventSubscriberInterface
* This function is called when the kernel encounters a request.
* It checks if the user must change its password or add an 2FA mehtod and redirect it to the user settings page,
* if needed.
* @param RequestEvent $event
*/
public function redirectToSettingsIfNeeded(RequestEvent $event) : void
public function redirectToSettingsIfNeeded(RequestEvent $event): void
{
$user = $this->security->getUser();
$request = $event->getRequest();
if(!$event->isMasterRequest()) {
if (!$event->isMasterRequest()) {
return;
}
if(!$user instanceof User) {
if (!$user instanceof User) {
return;
}
@ -98,35 +94,36 @@ class PasswordChangeNeededSubscriber implements EventSubscriberInterface
/* Dont redirect tree endpoints, as this would cause trouble and creates multiple flash
warnigs for one page reload */
if(strpos($request->getUri(), '/tree/') !== false) {
if (false !== strpos($request->getUri(), '/tree/')) {
return;
}
//Show appropriate message to user about the reason he was redirected
if($user->isNeedPwChange()) {
if ($user->isNeedPwChange()) {
$this->flashBag->add('warning', 'user.pw_change_needed.flash');
}
if(static::TFARedirectNeeded($user)) {
if (static::TFARedirectNeeded($user)) {
$this->flashBag->add('warning', 'user.2fa_needed.flash');
}
$event->setResponse($this->httpUtils->createRedirectResponse($request, static::REDIRECT_TARGET));
}
/**
* Check if a redirect because of a missing 2FA method is needed.
* That is the case if the group of the user enforces 2FA, but the user has neither Google Authenticator nor an
* U2F key setup.
* @param User $user The user for which should be checked if it needs to be redirected.
*
* @param User $user The user for which should be checked if it needs to be redirected.
*
* @return bool True if the user needs to be redirected.
*/
public static function TFARedirectNeeded(User $user) : bool
public static function TFARedirectNeeded(User $user): bool
{
$tfa_enabled = $user->isU2FAuthEnabled() || $user->isGoogleAuthenticatorEnabled();
if ($user->getGroup() !== null && $user->getGroup()->isEnforce2FA() && !$tfa_enabled) {
if (null !== $user->getGroup() && $user->getGroup()->isEnforce2FA() && !$tfa_enabled) {
return true;
}
@ -134,7 +131,7 @@ class PasswordChangeNeededSubscriber implements EventSubscriberInterface
}
/**
* @inheritDoc
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
@ -142,4 +139,4 @@ class PasswordChangeNeededSubscriber implements EventSubscriberInterface
KernelEvents::REQUEST => 'redirectToSettingsIfNeeded',
];
}
}
}

View file

@ -21,7 +21,6 @@
namespace App\EventSubscriber;
use App\Entity\UserSystem\U2FKey;
use Doctrine\ORM\EntityManagerInterface;
use R\U2FTwoFactorBundle\Event\RegisterEvent;
@ -51,9 +50,9 @@ class U2FRegistrationSubscriber implements EventSubscriberInterface
/** @return string[] **/
public static function getSubscribedEvents(): array
{
return array(
return [
'r_u2f_two_factor.register' => 'onRegister',
);
];
}
public function onRegister(RegisterEvent $event): void
@ -78,4 +77,4 @@ class U2FRegistrationSubscriber implements EventSubscriberInterface
$response = new RedirectResponse($this->router->generate('user_settings'));
$event->setResponse($response);
}
}
}