Browse Source

Force redirect the user to the admin dashboard connect through the admin login area

Thomas Rabaix 13 năm trước cách đây
mục cha
commit
fdf01f5421

+ 7 - 0
Controller/AdminSecurityController.php

@@ -16,6 +16,7 @@ use FOS\UserBundle\Controller\SecurityController;
 use Symfony\Component\DependencyInjection\ContainerAware;
 use Symfony\Component\Security\Core\SecurityContext;
 use Symfony\Component\Security\Core\Exception\AuthenticationException;
+use Symfony\Component\HttpFoundation\RedirectResponse;
 
 class AdminSecurityController extends SecurityController
 {
@@ -43,6 +44,12 @@ class AdminSecurityController extends SecurityController
         // last username entered by the user
         $lastUsername = (null === $session) ? '' : $session->get(SecurityContext::LAST_USERNAME);
 
+        if ($this->container->get('security.context')->isGranted('ROLE_ADMIN')) {
+            $refererUri = $request->server->get('HTTP_REFERER');
+
+            return new RedirectResponse($refererUri && $refererUri != $request->getUri() ? $refererUri : $this->container->get('router')->generate('sonata_admin_dashboard'));
+        }
+
         return $this->container->get('templating')->renderResponse('SonataUserBundle:Admin:Security/login.html.'.$this->container->getParameter('fos_user.template.engine'), array(
             'last_username' => $lastUsername,
             'error'         => $error,

+ 3 - 1
Resources/doc/reference/installation.rst

@@ -147,7 +147,6 @@ Then add a new custom firewall handlers for the admin
                 id: fos_user.user_manager
 
         firewalls:
-
             # -> custom firewall for the admin area of the URL
             admin:
                 pattern:      /admin(.*)
@@ -157,8 +156,11 @@ Then add a new custom firewall handlers for the admin
                     use_forward:    false
                     check_path:     /admin/login_check
                     failure_path:   null
+                    use_referer:    true
                 logout:
                     path:           /admin/logout
+                    target:         /admin/login
+
                 anonymous:    true
             # -> end custom configuration