Преглед изворни кода

Mise à jour authentification

François пре 5 година
родитељ
комит
2c6621e36d

+ 1 - 0
config/packages/security.yaml

@@ -22,6 +22,7 @@ security:
 
         main:
             anonymous: ~
+            user_checker: App\Security\UserChecker
             guard:
                 authenticators:
                     - App\Security\LoginFormAuthenticator

+ 1 - 1
src/Security/LoginFormAuthenticator.php

@@ -68,7 +68,7 @@ class LoginFormAuthenticator extends AbstractFormLoginAuthenticator
 
         if (!$user) {
             // fail authentication with a custom error
-            throw new CustomUserMessageAuthenticationException('Login non trouvé.');
+            throw new CustomUserMessageAuthenticationException('Login not found');
         }
 
         return $user;

+ 32 - 0
src/Security/UserChecker.php

@@ -0,0 +1,32 @@
+<?php
+
+namespace App\Security;
+
+use App\Entity\User as AppUser;
+use Symfony\Component\Security\Core\Exception\CredentialsExpiredException;
+use Symfony\Component\Security\Core\User\UserCheckerInterface;
+use Symfony\Component\Security\Core\User\UserInterface;
+
+class UserChecker implements UserCheckerInterface
+{
+    public function checkPreAuth(UserInterface $user)
+    {
+        if (!$user instanceof AppUser)
+        {
+            return;
+        }
+    }
+
+    public function checkPostAuth(UserInterface $user)
+    {
+        if (!$user instanceof AppUser)
+        {
+            dump($user);
+            return;
+        }
+        if (!$user->isEnabled())
+        {
+            throw new CredentialsExpiredException("Ce compte n'a pas été activé");
+        }
+    }
+}

+ 1 - 0
translations/security.fr.yaml

@@ -0,0 +1 @@
+Login not found: Identifiant non trouvé.