Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 81a30ebea6 | |||
| f87ed32f6f | |||
| 63398086b7 | |||
| 1454b9bfc8 | |||
| e299eb59ad | |||
| b6b82e1631 | |||
| a8bcc7ae43 | |||
| f2365c08e9 | |||
| 7a9dfa52db | |||
| ba83f4a075 | |||
| a515be554f | |||
| ec4919230b | |||
| 72d7add8d8 |
@@ -1,18 +1,10 @@
|
|||||||
###> symfony/framework-bundle ###
|
|
||||||
APP_ENV=dev
|
APP_ENV=dev
|
||||||
APP_SECRET=
|
APP_SECRET=
|
||||||
APP_SHARE_DIR=var/share
|
APP_SHARE_DIR=var/share
|
||||||
APP_VERSION=0.0.1
|
APP_VERSION=0.0.1
|
||||||
###< symfony/framework-bundle ###
|
|
||||||
|
|
||||||
###> doctrine/doctrine-bundle ###
|
|
||||||
DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&charset=utf8"
|
DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&charset=utf8"
|
||||||
###< doctrine/doctrine-bundle ###
|
MESSENGER_TRANSPORT_DSN="doctrine://default"
|
||||||
|
|
||||||
###> symfony/mailer ###
|
|
||||||
MAILER_DSN="smtp://localhost:1025"
|
MAILER_DSN="smtp://localhost:1025"
|
||||||
###< symfony/mailer ###
|
|
||||||
|
|
||||||
###> symfony/routing ###
|
|
||||||
DEFAULT_URI="http://localhost:8000"
|
DEFAULT_URI="http://localhost:8000"
|
||||||
###< symfony/routing ###
|
KAZ_API_USER=
|
||||||
|
KAZ_API_PASSWORD=
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
# Plateforme web pour les adhérents KAZ
|
# Plateforme web pour les adhérents KAZ
|
||||||
|
|
||||||
## Objectif
|
## Objectif
|
||||||
@@ -11,6 +10,7 @@ Cette application web permet aux adhérents de l'association KAZ de gérer leur
|
|||||||
|
|
||||||
## Architecture technique
|
## Architecture technique
|
||||||
- **Frontend** : [Twig](https://twig.symfony.com/) + [Tailwind CSS](https://tailwindcss.com/)
|
- **Frontend** : [Twig](https://twig.symfony.com/) + [Tailwind CSS](https://tailwindcss.com/)
|
||||||
|
- **Documentation installation Tailwind** : [Plus d'infos ici](https://tailwindcss.com/docs/installation/framework-guides/symfony)
|
||||||
- **Backend** : PHP 8.4 / [Symfony](https://symfony.com/)
|
- **Backend** : PHP 8.4 / [Symfony](https://symfony.com/)
|
||||||
- **Base de données** : [PostgreSQL](https://www.postgresql.org/)
|
- **Base de données** : [PostgreSQL](https://www.postgresql.org/)
|
||||||
- **Intégration** : Communication via API avec les outils de KAZ (notamment OpenLDAP).
|
- **Intégration** : Communication via API avec les outils de KAZ (notamment OpenLDAP).
|
||||||
@@ -18,7 +18,7 @@ Cette application web permet aux adhérents de l'association KAZ de gérer leur
|
|||||||
Cette base est conçue pour évoluer et intégrer de nouveaux outils et fonctionnalités à l'avenir.
|
Cette base est conçue pour évoluer et intégrer de nouveaux outils et fonctionnalités à l'avenir.
|
||||||
|
|
||||||
## Prérequis
|
## Prérequis
|
||||||
- **PHP** 8.4 ou supérieur
|
- **PHP** 8.4
|
||||||
- **[Composer](https://getcomposer.org/download/)** : (Gestionnaire de dépendances PHP)
|
- **[Composer](https://getcomposer.org/download/)** : (Gestionnaire de dépendances PHP)
|
||||||
- **[Symfony CLI](https://getcomposer.org/download/)** (Interface en ligne de commande Symfony)
|
- **[Symfony CLI](https://getcomposer.org/download/)** (Interface en ligne de commande Symfony)
|
||||||
- **Docker** Permet de lancer les services lié: postgres (base de données), mailpit (serveur de messagerie pour le dev)
|
- **Docker** Permet de lancer les services lié: postgres (base de données), mailpit (serveur de messagerie pour le dev)
|
||||||
@@ -31,34 +31,77 @@ Le projet suit les standards de développement suivants :
|
|||||||
- **[Git Flow](https://git-flow.readthedocs.io/fr/latest/presentation.html)** : Modèle de gestion de branches.
|
- **[Git Flow](https://git-flow.readthedocs.io/fr/latest/presentation.html)** : Modèle de gestion de branches.
|
||||||
- **[Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)** : Norme pour les messages de commit.
|
- **[Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)** : Norme pour les messages de commit.
|
||||||
|
|
||||||
|
### Procédure de contribution (Git Flow)
|
||||||
|
|
||||||
|
Toutes les modifications doivent passer par une branche dédiée avant d'être fusionnées dans la branche principal `main` via une Pull Request (Demande d'ajout).
|
||||||
|
|
||||||
|
#### Exemple d'ajout d'une fonctionnalité (feature)
|
||||||
|
1. **Mise à jour de l'environnement local** :
|
||||||
|
```bash
|
||||||
|
git checkout main
|
||||||
|
git pull origin main
|
||||||
|
```
|
||||||
|
2. **Création de la branche de fonctionnalité** (préfixe `feat/`) :
|
||||||
|
```bash
|
||||||
|
git checkout -b feat/nom-de-ma-feature
|
||||||
|
```
|
||||||
|
3. **Développement et commit** (respectant les Conventional Commits) :
|
||||||
|
```bash
|
||||||
|
git add .
|
||||||
|
git commit -m "feat: ajout de la nouvelle fonctionnalité"
|
||||||
|
```
|
||||||
|
4. **Publication de la branche** :
|
||||||
|
```bash
|
||||||
|
git push origin feat/nom-de-ma-feature
|
||||||
|
```
|
||||||
|
5. **Création de la Pull Request** : Rendez-vous sur Gitea pour ouvrir une PR de `feat/nom-de-ma-feature` vers `main`. Une fois revue et validée, elle sera fusionnée via l'interface.
|
||||||
|
|
||||||
|
#### Exemple de correction de bug (fix)
|
||||||
|
La procédure est identique, mais utilisez le préfixe `fix/` :
|
||||||
|
```bash
|
||||||
|
git checkout -b fix/nom-du-bug
|
||||||
|
# ... corrections ...
|
||||||
|
git commit -m "fix: résolution du problème"
|
||||||
|
git push origin fix/nom-du-bug
|
||||||
|
```
|
||||||
|
|
||||||
|
Pour les tâches de maintenance ou documentation, utilisez respectivement les préfixes `chore/` ou `docs/`.
|
||||||
|
|
||||||
## Quick start
|
## Quick start
|
||||||
|
|
||||||
### 1. Installation des dépendances
|
### 1. Clonage du projet
|
||||||
Clonez le projet et installez les dépendances avec Composer :
|
Clonez le projet en utilisant SSH :
|
||||||
|
```bash
|
||||||
|
git clone ssh://git@git.kaz.bzh:2202/melvin-leveque/interface-kaznautes.git
|
||||||
|
cd interface-kaznautes
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Installation des dépendances
|
||||||
|
Installez les dépendances avec Composer :
|
||||||
```bash
|
```bash
|
||||||
composer install
|
composer install
|
||||||
```
|
```
|
||||||
|
|
||||||
### 2. Configuration de l'environnement
|
### 3. Configuration de l'environnement
|
||||||
Copiez le fichier `.env` en `.env.local` et configurez vos accès à la base de données et à l'API :
|
Copiez le fichier `.env` en `.env.local` et configurez vos accès à la base de données et à l'API :
|
||||||
```bash
|
```bash
|
||||||
cp .env .env.local
|
cp .env .env.local
|
||||||
```
|
```
|
||||||
|
|
||||||
### 3. Base de données
|
### 4. Base de données
|
||||||
Créez la base de données et exécutez les migrations :
|
Créez la base de données et exécutez les migrations :
|
||||||
```bash
|
```bash
|
||||||
php bin/console doctrine:database:create
|
php bin/console doctrine:database:create
|
||||||
php bin/console doctrine:migrations:migrate
|
php bin/console doctrine:migrations:migrate
|
||||||
```
|
```
|
||||||
|
|
||||||
### 4. Installation des assets
|
### 5. Installation des assets
|
||||||
Le projet utilise AssetMapper. Installez les dépendances JS :
|
Le projet utilise AssetMapper. Installez les dépendances JS :
|
||||||
```bash
|
```bash
|
||||||
php bin/console importmap:install
|
php bin/console importmap:install
|
||||||
```
|
```
|
||||||
|
|
||||||
### 5. Lancement du serveur
|
### 6. Lancement du serveur
|
||||||
Utilisez le serveur Symfony pour lancer le projet localement :
|
Utilisez le serveur Symfony pour lancer le projet localement :
|
||||||
```bash
|
```bash
|
||||||
symfony serve -d
|
symfony serve -d
|
||||||
|
|||||||
@@ -1,81 +0,0 @@
|
|||||||
const nameCheck = /^[-_a-zA-Z0-9]{4,22}$/;
|
|
||||||
const tokenCheck = /^[-_/+a-zA-Z0-9]{24,}$/;
|
|
||||||
|
|
||||||
// Generate and double-submit a CSRF token in a form field and a cookie, as defined by Symfony's SameOriginCsrfTokenManager
|
|
||||||
// Use `form.requestSubmit()` to ensure that the submit event is triggered. Using `form.submit()` will not trigger the event
|
|
||||||
// and thus this event-listener will not be executed.
|
|
||||||
document.addEventListener('submit', function (event) {
|
|
||||||
generateCsrfToken(event.target);
|
|
||||||
}, true);
|
|
||||||
|
|
||||||
// When @hotwired/turbo handles form submissions, send the CSRF token in a header in addition to a cookie
|
|
||||||
// The `framework.csrf_protection.check_header` config option needs to be enabled for the header to be checked
|
|
||||||
document.addEventListener('turbo:submit-start', function (event) {
|
|
||||||
const h = generateCsrfHeaders(event.detail.formSubmission.formElement);
|
|
||||||
Object.keys(h).map(function (k) {
|
|
||||||
event.detail.formSubmission.fetchRequest.headers[k] = h[k];
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// When @hotwired/turbo handles form submissions, remove the CSRF cookie once a form has been submitted
|
|
||||||
document.addEventListener('turbo:submit-end', function (event) {
|
|
||||||
removeCsrfToken(event.detail.formSubmission.formElement);
|
|
||||||
});
|
|
||||||
|
|
||||||
export function generateCsrfToken (formElement) {
|
|
||||||
const csrfField = formElement.querySelector('input[data-controller="csrf-protection"], input[name="_csrf_token"]');
|
|
||||||
|
|
||||||
if (!csrfField) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let csrfCookie = csrfField.getAttribute('data-csrf-protection-cookie-value');
|
|
||||||
let csrfToken = csrfField.value;
|
|
||||||
|
|
||||||
if (!csrfCookie && nameCheck.test(csrfToken)) {
|
|
||||||
csrfField.setAttribute('data-csrf-protection-cookie-value', csrfCookie = csrfToken);
|
|
||||||
csrfField.defaultValue = csrfToken = btoa(String.fromCharCode.apply(null, (window.crypto || window.msCrypto).getRandomValues(new Uint8Array(18))));
|
|
||||||
}
|
|
||||||
csrfField.dispatchEvent(new Event('change', { bubbles: true }));
|
|
||||||
|
|
||||||
if (csrfCookie && tokenCheck.test(csrfToken)) {
|
|
||||||
const cookie = csrfCookie + '_' + csrfToken + '=' + csrfCookie + '; path=/; samesite=strict';
|
|
||||||
document.cookie = window.location.protocol === 'https:' ? '__Host-' + cookie + '; secure' : cookie;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function generateCsrfHeaders (formElement) {
|
|
||||||
const headers = {};
|
|
||||||
const csrfField = formElement.querySelector('input[data-controller="csrf-protection"], input[name="_csrf_token"]');
|
|
||||||
|
|
||||||
if (!csrfField) {
|
|
||||||
return headers;
|
|
||||||
}
|
|
||||||
|
|
||||||
const csrfCookie = csrfField.getAttribute('data-csrf-protection-cookie-value');
|
|
||||||
|
|
||||||
if (tokenCheck.test(csrfField.value) && nameCheck.test(csrfCookie)) {
|
|
||||||
headers[csrfCookie] = csrfField.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return headers;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function removeCsrfToken (formElement) {
|
|
||||||
const csrfField = formElement.querySelector('input[data-controller="csrf-protection"], input[name="_csrf_token"]');
|
|
||||||
|
|
||||||
if (!csrfField) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const csrfCookie = csrfField.getAttribute('data-csrf-protection-cookie-value');
|
|
||||||
|
|
||||||
if (tokenCheck.test(csrfField.value) && nameCheck.test(csrfCookie)) {
|
|
||||||
const cookie = csrfCookie + '_' + csrfField.value + '=0; path=/; samesite=strict; max-age=0';
|
|
||||||
|
|
||||||
document.cookie = window.location.protocol === 'https:' ? '__Host-' + cookie + '; secure' : cookie;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* stimulusFetch: 'lazy' */
|
|
||||||
export default 'csrf-protection-controller';
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
import { Controller } from '@hotwired/stimulus';
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This is an example Stimulus controller!
|
|
||||||
*
|
|
||||||
* Any element with a data-controller="hello" attribute will cause
|
|
||||||
* this controller to be executed. The name "hello" comes from the filename:
|
|
||||||
* hello_controller.js -> "hello"
|
|
||||||
*
|
|
||||||
* Delete this file or adapt it for your use!
|
|
||||||
*/
|
|
||||||
export default class extends Controller {
|
|
||||||
connect() {
|
|
||||||
this.element.textContent = 'Hello Stimulus! Edit me in assets/controllers/hello_controller.js';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
|
|
||||||
services:
|
|
||||||
###> doctrine/doctrine-bundle ###
|
|
||||||
database:
|
|
||||||
ports:
|
|
||||||
- "5432"
|
|
||||||
###< doctrine/doctrine-bundle ###
|
|
||||||
|
|
||||||
###> symfony/mailer ###
|
|
||||||
mailer:
|
|
||||||
image: axllent/mailpit
|
|
||||||
ports:
|
|
||||||
- "1025"
|
|
||||||
- "8025"
|
|
||||||
environment:
|
|
||||||
MP_SMTP_AUTH_ACCEPT_ANY: 1
|
|
||||||
MP_SMTP_AUTH_ALLOW_INSECURE: 1
|
|
||||||
###< symfony/mailer ###
|
|
||||||
+1
-1
@@ -3,7 +3,7 @@ services:
|
|||||||
database:
|
database:
|
||||||
image: postgres:${POSTGRES_VERSION:-16}-alpine
|
image: postgres:${POSTGRES_VERSION:-16}-alpine
|
||||||
ports:
|
ports:
|
||||||
- "5432"
|
- "5432:5432"
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_DB: ${POSTGRES_DB:-app}
|
POSTGRES_DB: ${POSTGRES_DB:-app}
|
||||||
# You should definitely change the password in production
|
# You should definitely change the password in production
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
# see https://symfony.com/doc/current/reference/configuration/framework.html
|
|
||||||
framework:
|
framework:
|
||||||
secret: '%env(APP_SECRET)%'
|
secret: '%env(APP_SECRET)%'
|
||||||
|
|
||||||
# Note that the session will be started ONLY if you read or write from it.
|
|
||||||
session: true
|
session: true
|
||||||
|
http_client:
|
||||||
|
scoped_clients:
|
||||||
|
kaz_api.client:
|
||||||
|
base_uri: '%env(KAZ_API_BASE_URL)%'
|
||||||
|
headers:
|
||||||
|
Accept: 'application/json'
|
||||||
|
|
||||||
#esi: true
|
# Section pour les tests
|
||||||
#fragments: true
|
|
||||||
|
|
||||||
when@test:
|
when@test:
|
||||||
framework:
|
framework:
|
||||||
test: true
|
test: true
|
||||||
|
|||||||
+8
-15
@@ -1,21 +1,14 @@
|
|||||||
# yaml-language-server: $schema=../vendor/symfony/dependency-injection/Loader/schema/services.schema.json
|
|
||||||
|
|
||||||
# This file is the entry point to configure your own services.
|
|
||||||
# Files in the packages/ subdirectory configure your dependencies.
|
|
||||||
# See also https://symfony.com/doc/current/service_container/import.html
|
|
||||||
|
|
||||||
# Put parameters here that don't need to change on each machine where the app is deployed
|
|
||||||
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
|
|
||||||
services:
|
services:
|
||||||
# default configuration for services in *this* file
|
# configuration par défaut pour les services
|
||||||
_defaults:
|
_defaults:
|
||||||
autowire: true # Automatically injects dependencies in your services.
|
autowire: true # Injecte automatiquement les dépendances dans vos services.
|
||||||
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
|
autoconfigure: true # Enregistre automatiquement vos services en tant que commandes, abonnés d'événements, etc.
|
||||||
|
|
||||||
# makes classes in src/ available to be used as services
|
|
||||||
# this creates a service per class whose id is the fully-qualified class name
|
|
||||||
App\:
|
App\:
|
||||||
resource: '../src/'
|
resource: '../src/'
|
||||||
|
|
||||||
# add more service definitions when explicit configuration is needed
|
App\Service\KazApiService:
|
||||||
# please note that last definitions always *replace* previous ones
|
arguments:
|
||||||
|
$kazApiClient: '@kaz_api.client'
|
||||||
|
$apiUser: '%env(KAZ_API_USER)%'
|
||||||
|
$apiPassword: '%env(KAZ_API_PASSWORD)%'
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?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 Version20260313104837 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('CREATE TABLE "user" (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, role VARCHAR(255) NOT NULL, mail VARCHAR(255) NOT NULL, mail_quota VARCHAR(255) NOT NULL, mail_de_secours VARCHAR(255) NOT NULL, identifiant_kaz VARCHAR(255) NOT NULL, quota VARCHAR(255) NOT NULL, has_nextcloud_access BOOLEAN NOT NULL, nextcloud_quota VARCHAR(255) NOT NULL, has_mobilizon BOOLEAN NOT NULL, has_agora_access BOOLEAN NOT NULL, PRIMARY KEY (id))');
|
||||||
|
$this->addSql('CREATE TABLE messenger_messages (id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, body TEXT NOT NULL, headers TEXT NOT NULL, queue_name VARCHAR(190) NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, available_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, delivered_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY (id))');
|
||||||
|
$this->addSql('CREATE INDEX IDX_75EA56E0FB7336F0E3BD61CE16BA31DBBF396750 ON messenger_messages (queue_name, available_at, delivered_at, id)');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this down() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('DROP TABLE "user"');
|
||||||
|
$this->addSql('DROP TABLE messenger_messages');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,7 +11,7 @@ class HomeController extends AbstractController
|
|||||||
#[Route('/hello')]
|
#[Route('/hello')]
|
||||||
public function hello(): Response
|
public function hello(): Response
|
||||||
{
|
{
|
||||||
return $this->render('hello.html.twig', [
|
return $this->render('home/hello.html.twig', [
|
||||||
'name' => 'Melvin'
|
'name' => 'Melvin'
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Service\KazApiService;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||||
|
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
|
||||||
|
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||||
|
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||||
|
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||||
|
|
||||||
|
class UserController extends AbstractController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Permet de vérifier si un utilisateur existe dans le ldap.
|
||||||
|
*
|
||||||
|
* @param string $email L'adresse e-mail de l'utilisateur.
|
||||||
|
* @param KazApiService $apiClient Le service utilisé pour récupérer les données utilisateur.
|
||||||
|
*
|
||||||
|
* @return Response La page index utilisateur rendue.
|
||||||
|
* @throws ClientExceptionInterface
|
||||||
|
* @throws DecodingExceptionInterface
|
||||||
|
* @throws RedirectionExceptionInterface
|
||||||
|
* @throws ServerExceptionInterface
|
||||||
|
* @throws TransportExceptionInterface
|
||||||
|
*/
|
||||||
|
#[Route('/user/{email}')]
|
||||||
|
public function index(string $email, KazApiService $apiClient): Response
|
||||||
|
{
|
||||||
|
$exist = $apiClient->getUserData($email);
|
||||||
|
|
||||||
|
return $this->render('user/index.html.twig', [
|
||||||
|
'exist' => $exist,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,179 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use App\Repository\UserRepository;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Symfony\Component\Validator\Constraints\Uuid;
|
||||||
|
|
||||||
|
#[ORM\Entity(repositoryClass: UserRepository::class)]
|
||||||
|
#[ORM\Table(name: '`user`')]
|
||||||
|
class User
|
||||||
|
{
|
||||||
|
#[ORM\Id]
|
||||||
|
#[ORM\GeneratedValue]
|
||||||
|
#[ORM\Column]
|
||||||
|
private ?Uuid $id ;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 255)]
|
||||||
|
private ?string $role = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 255)]
|
||||||
|
private ?string $mail = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 255)]
|
||||||
|
private ?string $mailQuota = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 255)]
|
||||||
|
private ?string $mailDeSecours = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 255)]
|
||||||
|
private ?string $identifiantKaz = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 255)]
|
||||||
|
private ?string $quota = null;
|
||||||
|
|
||||||
|
#[ORM\Column]
|
||||||
|
private ?bool $hasNextcloudAccess = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 255)]
|
||||||
|
private ?string $nextcloudQuota = null;
|
||||||
|
|
||||||
|
#[ORM\Column]
|
||||||
|
private ?bool $hasMobilizon = null;
|
||||||
|
|
||||||
|
#[ORM\Column]
|
||||||
|
private ?bool $hasAgoraAccess = null;
|
||||||
|
|
||||||
|
public function getId(): ?Uuid
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setId(Uuid $id): static
|
||||||
|
{
|
||||||
|
$this->id = $id;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRole(): ?string
|
||||||
|
{
|
||||||
|
return $this->role;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setRole(string $role): static
|
||||||
|
{
|
||||||
|
$this->role = $role;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMail(): ?string
|
||||||
|
{
|
||||||
|
return $this->mail;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setMail(string $mail): static
|
||||||
|
{
|
||||||
|
$this->mail = $mail;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMailQuota(): ?string
|
||||||
|
{
|
||||||
|
return $this->mailQuota;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setMailQuota(string $mailQuota): static
|
||||||
|
{
|
||||||
|
$this->mailQuota = $mailQuota;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMailDeSecours(): ?string
|
||||||
|
{
|
||||||
|
return $this->mailDeSecours;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setMailDeSecours(string $mailDeSecours): static
|
||||||
|
{
|
||||||
|
$this->mailDeSecours = $mailDeSecours;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getIdentifiantKaz(): ?string
|
||||||
|
{
|
||||||
|
return $this->identifiantKaz;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setIdentifiantKaz(string $identifiantKaz): static
|
||||||
|
{
|
||||||
|
$this->identifiantKaz = $identifiantKaz;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getQuota(): ?string
|
||||||
|
{
|
||||||
|
return $this->quota;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setQuota(string $quota): static
|
||||||
|
{
|
||||||
|
$this->quota = $quota;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hasNextcloudAccess(): ?bool
|
||||||
|
{
|
||||||
|
return $this->hasNextcloudAccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setHasNextcloudAccess(bool $hasNextcloudAccess): static
|
||||||
|
{
|
||||||
|
$this->hasNextcloudAccess = $hasNextcloudAccess;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getNextcloudQuota(): ?string
|
||||||
|
{
|
||||||
|
return $this->nextcloudQuota;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setNextcloudQuota(string $nextcloudQuota): static
|
||||||
|
{
|
||||||
|
$this->nextcloudQuota = $nextcloudQuota;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hasMobilizon(): ?bool
|
||||||
|
{
|
||||||
|
return $this->hasMobilizon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setHasMobilizon(bool $hasMobilizon): static
|
||||||
|
{
|
||||||
|
$this->hasMobilizon = $hasMobilizon;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hasAgoraAccess(): ?bool
|
||||||
|
{
|
||||||
|
return $this->hasAgoraAccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setHasAgoraAccess(bool $hasAgoraAccess): static
|
||||||
|
{
|
||||||
|
$this->hasAgoraAccess = $hasAgoraAccess;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Repository;
|
||||||
|
|
||||||
|
use App\Entity\User;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends ServiceEntityRepository<User>
|
||||||
|
*/
|
||||||
|
class UserRepository extends ServiceEntityRepository
|
||||||
|
{
|
||||||
|
public function __construct(ManagerRegistry $registry)
|
||||||
|
{
|
||||||
|
parent::__construct($registry, User::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * @return User[] Returns an array of User objects
|
||||||
|
// */
|
||||||
|
// public function findByExampleField($value): array
|
||||||
|
// {
|
||||||
|
// return $this->createQueryBuilder('u')
|
||||||
|
// ->andWhere('u.exampleField = :val')
|
||||||
|
// ->setParameter('val', $value)
|
||||||
|
// ->orderBy('u.id', 'ASC')
|
||||||
|
// ->setMaxResults(10)
|
||||||
|
// ->getQuery()
|
||||||
|
// ->getResult()
|
||||||
|
// ;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public function findOneBySomeField($value): ?User
|
||||||
|
// {
|
||||||
|
// return $this->createQueryBuilder('u')
|
||||||
|
// ->andWhere('u.exampleField = :val')
|
||||||
|
// ->setParameter('val', $value)
|
||||||
|
// ->getQuery()
|
||||||
|
// ->getOneOrNullResult()
|
||||||
|
// ;
|
||||||
|
// }
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Service;
|
||||||
|
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||||
|
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
|
||||||
|
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||||
|
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||||
|
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||||
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
|
|
||||||
|
class KazApiService
|
||||||
|
{
|
||||||
|
private ?string $token = null;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private readonly HttpClientInterface $kazApiClient,
|
||||||
|
private readonly string $apiUser,
|
||||||
|
private readonly string $apiPassword
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récupère le token JWT via l'authentification Basic
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* @throws ClientExceptionInterface
|
||||||
|
* @throws DecodingExceptionInterface
|
||||||
|
* @throws RedirectionExceptionInterface
|
||||||
|
* @throws ServerExceptionInterface
|
||||||
|
* @throws TransportExceptionInterface
|
||||||
|
*/
|
||||||
|
private function getToken(): string
|
||||||
|
{
|
||||||
|
if ($this->token) {
|
||||||
|
return $this->token;
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = $this->kazApiClient->request('POST', '/get_token', [
|
||||||
|
'auth_basic' => [$this->apiUser, $this->apiPassword]
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($response->getStatusCode() !== 200) {
|
||||||
|
throw new Exception('Impossible de récupérer le token JWT');
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = $response->toArray();
|
||||||
|
$this->token = $data['token']; // Ajustez la clé selon le format de votre API
|
||||||
|
|
||||||
|
return $this->token;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Permet de vérifier si un utilisateur existe dans le ldap.
|
||||||
|
*
|
||||||
|
* @param string $email L'adresse e-mail de l'utilisateur à rechercher.
|
||||||
|
*
|
||||||
|
* @return array Les données utilisateur renvoyées par l'API.
|
||||||
|
*
|
||||||
|
* @throws ClientExceptionInterface
|
||||||
|
* @throws DecodingExceptionInterface
|
||||||
|
* @throws RedirectionExceptionInterface
|
||||||
|
* @throws ServerExceptionInterface
|
||||||
|
* @throws TransportExceptionInterface
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function getUserData(string $email): array
|
||||||
|
{
|
||||||
|
$options['headers']['Authorization'] = 'Bearer ' . $this->getToken();
|
||||||
|
|
||||||
|
$response = $this->kazApiClient->request('GET', "/ldap/user/$email", $options);
|
||||||
|
|
||||||
|
if ($response->getStatusCode() !== 200) {
|
||||||
|
throw new Exception('Erreur lors de l\'appel API : ' . $response->getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response->toArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
error404.html.twig
|
||||||
Reference in New Issue
Block a user