0
votes

Within my cakephp app, I have a Users Table, with fields username, password, and role. The role determines which controllers and actions they can access. 2 types of main roles I have: Admin and Customer. Hence Admins and Customers should only be allowed to access their respective Controllers and Actions.

However under my AppController, it has only a single redirect for non logged in users that leads the same Controller and Action login page, regardless of whether it was a user trying access an admin page or customer page.

I would like to have 2 different login pages, one for Admins and one for Customers. How can I achieve this?

class AppController extends Controller {

    public $components = array(
        'DebugKit.Toolbar',
        'Session',
        'Auth'=>array(

            'loginRedirect'=>array('controller'=>'Access', 'action'=>'login'),  
            'logoutRedirect'=>array('controller'=>'Access', 'action'=>'logout'), 
            'authError'=>'You cannot access that page', 
            'authorize'=>array('Controller')

        )
    );
1
I don't know if your way is possible, but you can try redirecting admins after login to admin page instead default customer pagewalkingRed

1 Answers

0
votes

You forget to set loginAction .. class AppController extends Controller {

public $components = array(
    'DebugKit.Toolbar',
    'Session',
    'Auth'=>array(
        'loginAction'=>array('controller'=>'users','action'=>'login'),
        'loginRedirect'=>array('controller'=>'Access', 'action'=>'login'),  
        'logoutRedirect'=>array('controller'=>'Access', 'action'=>'logout'), 
        'authError'=>'You cannot access that page', 
        'authorize'=>array('Controller')

    )
);