Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Auth session not pass to security plugin beforeDispatch function

Hi All,

I have to deploy project to centos server and i have problem with security plugin.

In class SecurityPlugin and function beforeDispatch i have to call auth session that set from Login function like this.

Login function

$this->session->set('auth', array( 'accountno' => $userInfo['partnerAccountNo'], 'loginname' => $userInfo['firstName'], 'last_name' => $userInfo['lastName'], ));

And show that in beforeDispatch, but it can not get session

beforeDispatch function

$auth = $this->session->get('auth'); var_dump($auth);
if (!$auth){ $role = 'Guests'; } else { $role = 'Users'; }

the $auth variable show null after var_dump.

Pls help me, thanks



1.0k

Anyone pls help me



5.9k
Accepted
answer

You did initialize session within $di?

$di->setShared('session', function () {
    $session = new SessionAdapter();
    $session->start();

    return $session;
});

Also, you did attach the plugin to the eventsManager and eventsManager to dispatcher (and you did create a method beforeDispatch in SecurityPlugin.php)?

        $di->set('dispatcher', function() use ($config) {

            $eventsManager = new EventsManager();
            $eventsManager->attach('dispatch:beforeDispatch', new SecurityPlugin);

            $dispatcher = new Dispatcher();
            $dispatcher->setEventsManager($eventsManager);

            $dispatcher->setDefaultNamespace($config->application->modules->admin->defaultNamespace);

            return $dispatcher;
        });

Did you try with the beforeExecuteRoute() event instead of beforeDispatch?

Also did you register the namespace for the plugin in the loader (and then used that namespace)?

$loader->registerNamespaces(
    array(
        //...
        'Plugins'   => $config->application->pluginsDir,
        //'...
    )
);