SSO #1

Merged
Charles-Edouard merged 23 commits from SSO into main 2025-07-29 16:46:46 +02:00
11 changed files with 447 additions and 0 deletions
Showing only changes of commit 97da159794 - Show all commits

View File

@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250626124556 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql(<<<'SQL'
CREATE TABLE user_tab (id SERIAL NOT NULL, users_id INT NOT NULL, tab_open INT NOT NULL, PRIMARY KEY(id))
SQL);
$this->addSql(<<<'SQL'
CREATE INDEX IDX_98F5228767B3B43D ON user_tab (users_id)
SQL);
$this->addSql(<<<'SQL'
ALTER TABLE user_tab ADD CONSTRAINT FK_98F5228767B3B43D FOREIGN KEY (users_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE
SQL);
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql(<<<'SQL'
CREATE SCHEMA public
SQL);
$this->addSql(<<<'SQL'
ALTER TABLE user_tab DROP CONSTRAINT FK_98F5228767B3B43D
SQL);
$this->addSql(<<<'SQL'
DROP TABLE user_tab
SQL);
}
}

View File

@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250626134726 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql(<<<'SQL'
ALTER TABLE user_tab RENAME COLUMN tab_open TO ip_address
SQL);
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql(<<<'SQL'
CREATE SCHEMA public
SQL);
$this->addSql(<<<'SQL'
ALTER TABLE user_tab RENAME COLUMN ip_address TO tab_open
SQL);
}
}

View File

@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250626135125 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql(<<<'SQL'
ALTER TABLE user_tab ALTER ip_address TYPE VARCHAR(255)
SQL);
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql(<<<'SQL'
CREATE SCHEMA public
SQL);
$this->addSql(<<<'SQL'
ALTER TABLE user_tab ALTER ip_address TYPE INT
SQL);
}
}

View File

@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250626145913 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql(<<<'SQL'
ALTER TABLE user_tab ADD tab_id VARCHAR(255) DEFAULT NULL
SQL);
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql(<<<'SQL'
CREATE SCHEMA public
SQL);
$this->addSql(<<<'SQL'
ALTER TABLE user_tab DROP tab_id
SQL);
}
}

View File

@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250627073903 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql(<<<'SQL'
CREATE TABLE subscriptions (id SERIAL NOT NULL, users_id INT NOT NULL, PRIMARY KEY(id))
SQL);
$this->addSql(<<<'SQL'
CREATE INDEX IDX_4778A0167B3B43D ON subscriptions (users_id)
SQL);
$this->addSql(<<<'SQL'
ALTER TABLE subscriptions ADD CONSTRAINT FK_4778A0167B3B43D FOREIGN KEY (users_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE
SQL);
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql(<<<'SQL'
CREATE SCHEMA public
SQL);
$this->addSql(<<<'SQL'
ALTER TABLE subscriptions DROP CONSTRAINT FK_4778A0167B3B43D
SQL);
$this->addSql(<<<'SQL'
DROP TABLE subscriptions
SQL);
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\Controller;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Mercure\HubInterface;
use Symfony\Component\Mercure\Update;
class MercureController extends AbstractController
{
public function publish(HubInterface $hub): Response
{
$update = new Update(
'http://solutions-easy.moi/connect',
json_encode(['status' => 'OutOfStock'])
);
$hub->publish($update);
return new Response('published!');
}
}

View File

@ -0,0 +1,36 @@
<?php
namespace App\Entity;
use App\Repository\SubscriptionsRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: SubscriptionsRepository::class)]
class Subscriptions
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'subscriptions')]
#[ORM\JoinColumn(nullable: false)]
private ?User $users = null;
public function getId(): ?int
{
return $this->id;
}
public function getUsers(): ?User
{
return $this->users;
}
public function setUsers(?User $users): static
{
$this->users = $users;
return $this;
}
}

66
src/Entity/UserTab.php Normal file
View File

@ -0,0 +1,66 @@
<?php
namespace App\Entity;
use App\Repository\UserTabRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: UserTabRepository::class)]
class UserTab
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: false)]
private ?User $users = null;
#[ORM\Column]
private ?String $ipAddress = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $tabId = null;
public function getId(): ?int
{
return $this->id;
}
public function getUsers(): ?User
{
return $this->users;
}
public function setUsers(?User $users): static
{
$this->users = $users;
return $this;
}
public function getIpAddress(): ?String
{
return $this->ipAddress;
}
public function setIpAddres(String $ipAddress): static
{
$this->ipAddress = $ipAddress;
return $this;
}
public function getTabId(): ?string
{
return $this->tabId;
}
public function setTabId(?string $tabId): static
{
$this->tabId = $tabId;
return $this;
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class LogoutSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
'kernel.response' => 'onKernelResponse',
];
}
public function onKernelResponse($event): void
{
// // This method can be used to perform actions after a logout response is sent.
// // For example, you could log the logout event or clear session data.
//
//// Example: Log the logout event
// $logger = $this->container->get('logger');
// $logger->info('User logged out successfully.');
}
}

View File

@ -0,0 +1,43 @@
<?php
namespace App\Repository;
use App\Entity\Subscriptions;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Subscriptions>
*/
class SubscriptionsRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Subscriptions::class);
}
// /**
// * @return Subscriptions[] Returns an array of Subscriptions objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('s')
// ->andWhere('s.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('s.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Subscriptions
// {
// return $this->createQueryBuilder('s')
// ->andWhere('s.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}

View File

@ -0,0 +1,44 @@
{% extends 'base.html.twig' %}
{% block title %}Test - index{% endblock %}
{#{% block jaa %}#}
{# <script>#}
{# const eventSource = new EventSource("{{ mercure('http://solutions-easy.moi/connect')|raw }}");#}
{# eventSource.onmessage = event => {#}
{# console.log(JSON.parse(event))#}
{# // You can update the UI or handle the message as needed#}
{# };#}
{# </script>#}
{#{% endblock %}#}
{% block body %}
{% if app.user %}
<div class="mb-3">
You are logged in as {{ app.user.userIdentifier }}, <a href="{{ path('app_logout') }}">Logout</a>
</div>
{% endif %}
<h1>Testing Page</h1>
{# <h2>Active Tabs per User</h2>#}
{# <ul>#}
{# {% for topic, count in counts %}#}
{# <li>{{ topic }}: {{ count }} tab(s) open</li>#}
{# {% endfor %}#}
{# </ul>#}
{# <h2>All Subscriptions</h2>#}
{# <ul>#}
{# {% for sub in subscriptions %}#}
{# <li>#}
{# Topic: {{ sub.topic }}<br>#}
{# Subscriber: {{ sub.subscriber }}<br>#}
{# Active: {{ sub.active ? 'Yes' : 'No' }}#}
{# </li>#}
{# {% endfor %}#}
{# </ul>#}
{# {{ mercure('http://portail.solutions-easy.moi/connect?userId=' ~ app.user.userIdentifier) }}#}
{% endblock %}