You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.0 KiB
PHP
38 lines
1.0 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;
|
|
|
|
/**
|
|
* Check if a user is valid for authentification
|
|
*
|
|
* The user must have:
|
|
* - Verified his email
|
|
* - Account validated by administrator
|
|
*/
|
|
class UserChecker implements UserCheckerInterface {
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function checkPreAuth (UserInterface $user): void {
|
|
if (!$user instanceof User) {
|
|
return;
|
|
}
|
|
|
|
if (!$user->isVerified()) {
|
|
throw new CustomUserMessageAccountStatusException('user.emailNotVerified');
|
|
}
|
|
if ($user->getValidationAdministrator() === null || $user->getValidationDate() === null) {
|
|
throw new CustomUserMessageAccountStatusException('user.notValidatedByAdmin');
|
|
}
|
|
}
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function checkPostAuth (UserInterface $user): void {
|
|
}
|
|
} |