jun 3
This commit is contained in:
@@ -8,6 +8,7 @@ use App\Entity\Conference;
|
||||
use App\Form\CommentType;
|
||||
use App\Repository\CommentRepository;
|
||||
use App\Repository\ConferenceRepository;
|
||||
use App\SpamChecker;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
@@ -35,6 +36,7 @@ class ConferenceController extends AbstractController
|
||||
Request $request,
|
||||
Conference $conference,
|
||||
CommentRepository $commentRepository,
|
||||
SpamChecker $spamChecker,
|
||||
ConferenceRepository $conferenceRepository,
|
||||
#[Autowire('%photo_dir%')] string $photoDir,
|
||||
): Response {
|
||||
@@ -50,6 +52,15 @@ class ConferenceController extends AbstractController
|
||||
$comment->setPhotoFilename($filename);
|
||||
}
|
||||
$this->entityManager->persist($comment);
|
||||
$context = [
|
||||
'user_ip' => $request->getClientIp(),
|
||||
'user_agent' => $request->headers->get('user-agent'),
|
||||
'referrer' => $request->headers->get('referer'),
|
||||
'permalink' => $request->getUri(),
|
||||
];
|
||||
if (2 === $spamChecker->getSpamScore($comment, $context)) {
|
||||
throw new \RuntimeException('Blatant spam, go away!');
|
||||
}
|
||||
$this->entityManager->flush();
|
||||
|
||||
return $this->redirectToRoute('conference', ['slug' => $conference->getSlug()]);
|
||||
|
||||
32
src/Controller/SecurityController.php
Normal file
32
src/Controller/SecurityController.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
||||
|
||||
class SecurityController extends AbstractController
|
||||
{
|
||||
#[Route(path: '/login', name: 'app_login')]
|
||||
public function login(AuthenticationUtils $authenticationUtils): Response
|
||||
{
|
||||
// get the login error if there is one
|
||||
$error = $authenticationUtils->getLastAuthenticationError();
|
||||
|
||||
// last username entered by the user
|
||||
$lastUsername = $authenticationUtils->getLastUsername();
|
||||
|
||||
return $this->render('security/login.html.twig', [
|
||||
'last_username' => $lastUsername,
|
||||
'error' => $error,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route(path: '/logout', name: 'app_logout')]
|
||||
public function logout(): void
|
||||
{
|
||||
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user