multiple login in cakephp 3

576 Views Asked by At

I have to create on seperate login screen for user vendor type. Under the Appcontroller I have added

public function beforeFilter(Event $event){

    $this->Auth->allow(['login', 'logout','vendor_login','vendor_logout']);

}

    $this->loadComponent('Auth', [
            'authorize' => [
                    'Acl.Actions' => ['actionPath' => 'controllers/']
            ],
            'loginAction' => [
                    'plugin' => false,
                    'controller' => 'Users',
                    'action' => 'login'
            ],
            'loginRedirect' => [
                    'plugin' => false,
                    'controller' => 'Pages',
                    'action' => 'display',
                    'home'
            ],
            'logoutRedirect' => [
                    'plugin' => false,
                    'controller' => 'Users',
                    'action' => 'login'
            ],  
            'vendorLoginAction' => [
                    'plugin' => false,
                    'controller' => 'Users',
                    'action' => 'vendorLogin'
            ],
            'vendorLoginRedirect' => [
                    'plugin' => false,
                    'controller' => 'BoldNumberRequest',
                    'action' => 'index',
                    'home'
            ],
            'vendorLogoutRedirect' => [
                    'plugin' => false,
                    'controller' => 'Users',
                    'action' => 'vendorLogout'
            ],
            'unauthorizedRedirect' => [
                    'controller' => 'Pages',
                    'action' => 'display',
                    'prefix' => false
            ],
            'authError' => 'You are not authorized to access that location.',
            'flash' => [
                    'element' => 'error'
            ]
    ]);

vendorLogin function and vendor_login.ctp has been created for users. In the route.php file i have added

Router::scope('/', function (RouteBuilder $vendorroutes) {
    $vendorroutes->setExtensions(['json', 'xml','pdf']);
    $vendorroutes->connect('/', ['controller' => 'Users', 'action' => 'vendorLogin']);
    $vendorroutes->connect('/boldnumberrequest/*', ['controller' => 'BoldNumberRequest', 'action' => 'index-vendor']);

    $routes->fallbacks(DashedRoute::class);
});
Router::prefix('vendorLogin', function ($vendorroutes) {
    $vendorroutes->fallbacks('DashedRoute');
});

Vendor login screen is coming but after login it should redirect to http://localhost/polymer_erp/bold-number-request/index but it's redirecting to http://localhost/polymer_erp/pages/home that is default for other login user. Is this procedure is correct and how can i change the default redirect after login.?

0

There are 0 best solutions below