41 lines
1.4 KiB
PHP
41 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Security;
|
|
|
|
use App\Entity\User;
|
|
use Symfony\Component\Security\Core\Exception\CustomUserMessageAccountStatusException;
|
|
use Symfony\Component\Security\Core\User\UserCheckerInterface;
|
|
use Symfony\Component\Security\Core\User\UserInterface;
|
|
|
|
class UserChecker implements UserCheckerInterface
|
|
{
|
|
public function checkPreAuth(UserInterface $user): void
|
|
{
|
|
if (!$user instanceof User) {
|
|
return;
|
|
}
|
|
|
|
// checked before the block, as a deletion is the stronger statement and its
|
|
// message has to win when an account carries both
|
|
if (true === $user->isDeleted()) {
|
|
throw new CustomUserMessageAccountStatusException('Dein Account wurde gelöscht. Wende dich an das Team, wenn du ihn wiederherstellen möchtest.');
|
|
}
|
|
|
|
if (true === $user->isDisabled()) {
|
|
throw new CustomUserMessageAccountStatusException('Dein Account wurde gesperrt: '.$user->getDisabledReason());
|
|
}
|
|
|
|
if ([] === array_intersect($user->getRoles(), array_keys(User::ROLES))) {
|
|
if ([] !== $user->getPendingRoles()) {
|
|
throw new CustomUserMessageAccountStatusException('Dein Account wurde noch nicht freigeschaltet.');
|
|
}
|
|
|
|
throw new CustomUserMessageAccountStatusException('Keine gültige Rolle zugewiesen.');
|
|
}
|
|
}
|
|
|
|
public function checkPostAuth(UserInterface $user): void
|
|
{
|
|
}
|
|
}
|