Я не буду обновлять действие (добавлять +1 к количеству логинов и обновлять временную метку последнего входа) в базу данных, когда пользователь успешно войдет в систему. Использование Symfony 3Symfony выполняет действие при входе пользователя
я добавил Листер:
// src/AppBundle/Listener/SecurityListener.php
namespace AppBundle\Listener;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
#use Doctrine\Bundle\DoctrineBundle\Registry as Doctrine;
use Doctrine\ORM\EntityManager;
class SecurityListener
{
private $tokenStorage;
public function __construct(TokenStorage $tokenStorage, EntityManager $doctrine)
{
}
public function onSecurityInteractiveLogin(InteractiveLoginEvent $event)
{
if ($this->tokenStorage->isGranted('IS_AUTHENTICATED_FULLY')) {
if($user = $event->getAuthenticationToken()->getUser())
var_dump($user);
else {
var_dump('nej');
}
}
/**
* Update lastLogin and loginCount for user in database
*/
// $em->
}
}
приложение/Config/services.yml:
# Learn more about services, parameters and containers at
# http://symfony.com/doc/current/service_container.html
parameters:
# parameter_name: value
account.security_listener.class: AppBundle\Listener\SecurityListener
services:
# service_name:
# class: AppBundle\Directory\ClassName
# arguments: ["@another_service_name", "plain_value", "%parameter_name%"]
account.security_listener:
class: %account.security_listener.class%
arguments: ['@security.token_storage', '@doctrine.orm.entity_manager']
tags:
- { name: kernel.event_listener, event: security.interactive_login, method: onSecurityInteractiveLogin }
Я получаю ошибку Error: Call to a member function isGranted() on null
Какова услуга для этого InteractiveLoginEvent? Я получаю сообщение об ошибке: «Служба« account.security_listener »имеет зависимость от несуществующей службы« security.interactiveloginevent ». Я также пытался с security.event – Diamonte
та же ошибка с @ security.interactive_login – Diamonte
Вам не нужно измените ваши services.yml. Вам просто нужно обновить метод 'onSecurityInteractiveLogin' класса' AppBundle \ Listener \ SecurityListener'. –