PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, November 1, 2022

[FIXED] how to set different auth redirect url for different user group in cakedc plugin cakephp3

 November 01, 2022     cakedc, cakephp-3.x     No comments   

Issue

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


Solution

I can think about 2 options:

  • Override EVENT_AFTER_LOGIN (more complex)
  • 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.



Answered By - steinkel
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing