<?php
namespace OwrBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="session")
* @ORM\HasLifecycleCallbacks
*/
class Session
{
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
protected $id;
/**
* @ORM\Column(type="string", name="session", unique=true)
*/
protected $session;
/**
* @ORM\ManyToOne(targetEntity="User", inversedBy="session")
* @ORM\JoinColumn(name="user_id", referencedColumnName="user_id")
*/
protected $user;
/**
* @ORM\Column(type="datetime")
*/
protected $date;
<?php
namespace OwrBundle\Services;
use OwrBundle\Entity\Session;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
use Doctrine\Common\Persistence\ObjectManager;
class LoginListener
{
protected $doctrine;
protected $session;
public function __construct(ObjectManager $doctrine, $session)
{
$this->doctrine = $doctrine;
$this->session = $session;
}
public function onLogin(InteractiveLoginEvent $event)
{
$user = $event->getAuthenticationToken()->getUser();
$em = $this->doctrine;
if($user) {
$session = new Session();
$session->setSession($this->session->getId());
$session->setUser($user);
$em->persist($session);
$user->addSession($session);
$em->persist($user);
$em->flush();
$em->createQueryBuilder()
->delete('OwrBundle:Session', 's')
->where('s.date < ?1')
->setParameter(1, (new \DateTime(''))->modify('-1 month'))
->getQuery()
->getResult();
}
}
}
public function onOpen(ConnectionInterface $conn) {
$sessionDB = $this
->em
->getRepository('OwrBundle:Session')
->findOneBy([
'session' => $conn->Session->getId()
]);
if ($sessionDB && $user = $sessionDB->getUser()) {
$conn->user = $user->getId();
$this->connections[ $conn->resourceId ] = $conn;
$this->relations[ $user->getId() ][] = $conn->resourceId;
$this->users[ $user->getId() ] = $user;
} else {
$conn->close();
}
}
public function onMessage(ConnectionInterface $from, $msg) {
if (!array_key_exists($from->user, $this->users)) {
return;
}
//....
}
global
log 127.0.0.1 local0
maxconn 10000
daemon
defaults
mode http
log global
option httplog
retries 3
backlog 10000
timeout client 30s
timeout connect 30s
timeout server 30s
timeout tunnel 3600s
timeout http-keep-alive 1s
timeout http-request 15s
frontend public
bind *:8883 ssl crt /etc/letsencrypt/live/example.fr/fullchain.pem
acl is_websocket hdr(Upgrade) -i WebSocket
use_backend ws if is_websocket
default_backend www
backend ws
server ws1 127.0.0.1:8888
backend www
timeout server 30s
server www1 127.0.0.1:8080
-----BEGIN CERTIFICATE-----
MIIFEDCCA/igAwIBAgISBE9YKaojEhwVAiDsAtPq5dIMMA0GCSqGSIb3DQEBCwUA
MEoxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MSMwIQYDVQQD
ExpMZXQncyBFbmNyeXB0IEF1dGhvcml0eSBYMzAeFw0xNzExMzAyMTMzMDdaFw0x
ODAyMjgyMTMzMDdaMBgxFjAUBgNVBAMTDW9uZXdheXJlbnQuZnIwggEiMA0GCSqG
SIb3DQEBAQUAA4IBDwAwggEKAoIBAQD4jFLx8UaJ2YJmb8e1hHuGwjPwDXXj66DE
CMZwWZU1ilacOPu9SLBUgHjdNdI1X3eR9cbJUJ2ncMgggw6L5ELGI4WoVgP5SPgx
Dmydq/pE/dhOUwvWwhPA2YMy8fMP44zmlzBh+sAPRVBDiigi/MfyR/2KASCzDmgs
f2rnF5h1M57v/4IqK3wtimDZTaO40Ac1HDozleDINVqB0ttxMc7Efw6Rl7MmD6jN
rYlFCH/vkOE5RIP2WlN03BGTI+Lb/r/E3t/fLGGJ9SgCQT8s4vXVgJ7X3WdS62vt
Q/PD3RSxojVvxwEZWpqCdPm+x9xaG3bqtgilBeCTv0xYAZamNJ6xAgMBAAGjggIg
MIICHDAOBgNVHQ8BAf8EBAMCBaAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUF
BwMCMAwGA1UdEwEB/wQCMAAwHQYDVR0OBBYEFHJPFdZ7QEHYd6BMP5tyR8tK/sIT
MB8GA1UdIwQYMBaAFKhKamMEfd265tE5t6ZFZe/zqOyhMG8GCCsGAQUFBwEBBGMw
YTAuBggrBgEFBQcwAYYiaH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