Am using cakephp3 and cakedc plugin. I have two user groups , 1 is normal user and other is super user
what i am basically looking for is setting different auth url for different user as both user group have different dashbaord.
I tried to hook UsersAuthComponent::EVENT_AFTER_LOGIN
.This is my code in eventListener
$helper = new AppView();
$adminDashBoard = $helper->Url->build([
'prefix' => 'admin',
'controller' =>'users',
'action' => 'dashboard',
'plugin' => null
]);
$customerDashBoard = $helper->Url->build([
'prefix' => 'customer',
'controller' =>'customers',
'action' => 'dashboard',
'plugin' => null
]);
$result = array();
if($entity['is_superuser'] == 1)
$result[] = $adminDashBoard;
else
$result[] = $customerDashBoard;
return $result;
I had to create object of AppView as Url builder was not available in EventLister
. Above code is working fine but the url that i have appended in result object gets appended in current URL and it becomes like
domain.com/<user's dashboard url in urlencoded format>
but i want it to redirect to user's dashboard url which i had set in eventListner
Any help will be appreciated
I can think about 2 options:
Create a dashboard action, and 2 different views 1 of each role. Then in the dashboard action you can do something like
if ($role === ROLE_ADMIN) { $this->render('dashboard_admin'); } else { $this->render('dashboard_user'); }
I think option 2 is simple enough to use it, you can extract the common markup from the views into an element and reuse it in both.