Skip to content
Snippets Groups Projects
Select Git revision
  • ef057002483c28e8a2d7e8dd3deeaf88e96c17d3
  • master default protected
  • release-1.3.10
  • popover-bootstrap-3.4
  • zf-3.x
  • 3.0.9
  • 3.0.8
  • 1.3.10
  • 3.0.7
  • 3.0.6
  • 3.0.5
  • 3.0.4
  • 3.0.3
  • 3.0.2
  • 3.0.1
  • 3.0.0
  • 1.3.9
  • 1.3.8
  • 1.3.7
  • 1.3.6
  • 1.3.5
  • 1.3.4
  • 1.3.3
  • 1.3.2
  • 1.3.1
25 results

Module.php

Blame
  • Forked from lib / unicaen / auth
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    Module.php 4.82 KiB
    <?php
    
    namespace UnicaenAuth;
    
    use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
    use Zend\ModuleManager\Feature\ConfigProviderInterface;
    use Zend\ModuleManager\Feature\ServiceProviderInterface;
    
    /**
     * Point d'entrée du module d'authentification Unicaen.
     *
     * @author Bertrand GAUTHIER <bertrand.gauthier@unicaen.fr>
     */
    class Module implements AutoloaderProviderInterface, ConfigProviderInterface, ServiceProviderInterface
    {
        /**
         *
         * @return array
         * @see ConfigProviderInterface
         */
        public function getConfig()
        {
            return include __DIR__ . '/config/module.config.php';
        }
    
    
    
        /**
         *
         * @return array
         * @see AutoloaderProviderInterface
         */
        public function getAutoloaderConfig()
        {
            return [
                'Zend\Loader\ClassMapAutoloader' => [
                    __DIR__ . '/autoload_classmap.php',
                ],
                'Zend\Loader\StandardAutoloader' => [
                    'namespaces' => [
                        __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
                    ],
                ],
            ];
        }
    
    
    
        /**
         * This method is called once the MVC bootstrapping is complete,
         * after the "loadModule.post" event, once $application->bootstrap() is called.
         *
         * @param EventInterface $e
         *
         * @see BootstrapListenerInterface
         */
        public function onBootstrap(\Zend\EventManager\EventInterface $e)
            /* @var \Zend\Mvc\MvcEvent $e */
        {
            $application = $e->getApplication();
            /* @var $services \Zend\ServiceManager\ServiceManager */
            $services = $application->getServiceManager();
    
            // transmission des ACL aux aides de vue de navigation
            try {
                $authorizeService = $services->get('BjyAuthorize\Service\Authorize');
                /* @var $authorizeService \BjyAuthorize\Service\Authorize */
                \Zend\View\Helper\Navigation::setDefaultAcl($authorizeService->getAcl());
                \Zend\View\Helper\Navigation::setDefaultRole($authorizeService->getIdentity());
            } catch (\Zend\ServiceManager\Exception\ServiceNotFoundException $snfe) {
                // pas de module BjyAuthorize : pas d'ACL
            }
    
            /* @var $options Options\ModuleOptions */
            $options = $services->get('unicaen-auth_module_options');
    
            // si l'auth CAS est demandée, modif de la route de connexion pour zapper le formulaire
            if ($options->getCas() && php_sapi_name() !== 'cli') {
                /* @var $router \Zend\Mvc\Router\Http\TreeRouteStack */
                $router = $services->get('router');
                $router->addRoutes([
                    // remplace les routes existantes (cf. config du module)
                    'zfcuser' => [
                        'type'          => 'Literal',
                        'priority'      => 1000,
                        'options'       => [
                            'route'    => '/auth',
                            'defaults' => [
                                'controller' => 'zfcuser',
                                'action'     => 'index',
                            ],
                        ],
                        'may_terminate' => true,
                        'child_routes'  => [
                            'login'  => [
                                'type'    => 'Literal',
                                'options' => [
                                    'route'    => '/connexion',
                                    'defaults' => [
                                        'controller' => 'zfcuser',
                                        'action'     => 'authenticate', // zappe l'action 'login'
                                    ],
                                ],
                            ],
                            'logout' => [
                                'type'    => 'Literal',
                                'options' => [
                                    'route'    => '/deconnexion',
                                    'defaults' => [
                                        'controller' => 'zfcuser',
                                        'action'     => 'logout',
                                    ],
                                ],
                            ],
                        ],
                    ],
                ]);
            }
        }
    
    
    
        /**
         *
         * @return array
         * @see ServiceProviderInterface
         */
        public function getServiceConfig()
        {
            return [
                'factories' => [
                    // verrue pour forcer le label de l'identifiant qqsoit l'options 'auth_identity_fields'
                    'zfcuser_login_form' => function ($sm) {
                        $options = $sm->get('zfcuser_module_options');
                        $form    = new \ZfcUser\Form\Login(null, $options);
                        $form->setInputFilter(new \ZfcUser\Form\LoginFilter($options));
                        $form->get('identity')->setLabel("Username");
    
                        return $form;
                    },
                ],
            ];
        }
    }