+
Utilisateur
Role
+
Statut
Aucun utilisateur.
@@ -15,7 +16,7 @@
{{ user.username }}
{{ getRoleLabels(user.roles) }}
+
+ Verrouillé
+ Actif
+
diff --git a/frontend/services/dto/user-data.ts b/frontend/services/dto/user-data.ts
index 3fb9206..ac89e35 100644
--- a/frontend/services/dto/user-data.ts
+++ b/frontend/services/dto/user-data.ts
@@ -2,16 +2,19 @@ export interface UserData {
id: number
username: string
roles: string[]
+ isLocked: boolean
}
export type UserPayload = {
username?: string
password?: string
roles?: string[]
+ isLocked?: boolean
}
export type UserFormData = {
username: string
password: string
role: string
+ isLocked: boolean
}
diff --git a/frontend/stores/auth.ts b/frontend/stores/auth.ts
index 4bd5e33..76447c5 100644
--- a/frontend/stores/auth.ts
+++ b/frontend/stores/auth.ts
@@ -1,6 +1,6 @@
import {defineStore} from 'pinia'
import type {UserData} from '~/services/dto/user-data'
-import {getCurrentUser, createUser, login, logout} from '~/services/auth'
+import {getCurrentUser, createUser, updateUser, login, logout} from '~/services/auth'
import type {UserPayload} from "~/services/dto/user-data";
import {ROLE} from '~/utils/constants'
@@ -58,7 +58,7 @@ export const useAuthStore = defineStore('auth', {
},
async updateUser(id: number, payload: UserPayload) {
this.isLoading = true
- const result = await createUser(payload).finally(() => {
+ const result = await updateUser(id, payload).finally(() => {
this.isLoading = false
})
return result
diff --git a/migrations/Version20260325142815.php b/migrations/Version20260325142815.php
new file mode 100644
index 0000000..2c31a51
--- /dev/null
+++ b/migrations/Version20260325142815.php
@@ -0,0 +1,31 @@
+addSql('ALTER TABLE "user" ADD is_locked BOOLEAN DEFAULT false NOT NULL');
+ }
+
+ public function down(Schema $schema): void
+ {
+ // this down() migration is auto-generated, please modify it to your needs
+ $this->addSql('ALTER TABLE public."user" DROP is_locked');
+ }
+}
diff --git a/src/Entity/User.php b/src/Entity/User.php
index 2427f0d..ce8015a 100644
--- a/src/Entity/User.php
+++ b/src/Entity/User.php
@@ -9,12 +9,14 @@ use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
+use App\State\ActiveUsersProvider;
use App\State\MeProvider;
use App\State\UserPasswordProcessor;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Serializer\Attribute\Groups;
+use Symfony\Component\Serializer\Attribute\SerializedName;
#[ORM\Entity]
#[ORM\Table(name: 'user', schema: 'public')]
@@ -45,7 +47,8 @@ use Symfony\Component\Serializer\Attribute\Groups;
),
new GetCollection(
normalizationContext: ['groups' => ['user-login:read']],
- security: "is_granted('PUBLIC_ACCESS')"
+ security: "is_granted('PUBLIC_ACCESS')",
+ provider: ActiveUsersProvider::class
),
new GetCollection(
uriTemplate: '/admin/users',
@@ -76,6 +79,11 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
#[Groups(['user:write'])]
private string $password = '';
+ #[ORM\Column(type: 'boolean', options: ['default' => false])]
+ #[Groups(['user:read', 'user:write'])]
+ #[SerializedName('isLocked')]
+ private bool $isLocked = false;
+
public function getId(): ?int
{
return $this->id;
@@ -125,6 +133,18 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
return $this;
}
+ public function getIsLocked(): bool
+ {
+ return $this->isLocked;
+ }
+
+ public function setIsLocked(bool $isLocked): self
+ {
+ $this->isLocked = $isLocked;
+
+ return $this;
+ }
+
public function eraseCredentials(): void
{
// No-op: we don't store temporary sensitive data on the entity.
diff --git a/src/Security/UserChecker.php b/src/Security/UserChecker.php
new file mode 100644
index 0000000..873eb9b
--- /dev/null
+++ b/src/Security/UserChecker.php
@@ -0,0 +1,27 @@
+getIsLocked()) {
+ throw new CustomUserMessageAccountStatusException('Ce compte est verrouillé.');
+ }
+ }
+
+ public function checkPostAuth(UserInterface $user, ?TokenInterface $token = null): void {}
+}
diff --git a/src/State/ActiveUsersProvider.php b/src/State/ActiveUsersProvider.php
new file mode 100644
index 0000000..1ecf4e3
--- /dev/null
+++ b/src/State/ActiveUsersProvider.php
@@ -0,0 +1,20 @@
+em->getRepository(User::class)->findBy(['isLocked' => false]);
+ }
+}