Authenticate user with two roles: one in mysql and other in mongo db

Hi, I have an application that controls the customer payments. My app have a sidebar with 5 option. I have 2 database: 1. Mysql that is used to authenticate it has a cam name role: user and admin. 2. Mongodb it has customer payments info. In that second databse I have a camp name–> comprobante: 1 or 0. I want to validate the loging with role from mysql and comprobante from mongodb comprobante. If my customer has role: user and comprobante: 1. I want to show 5 option in my side bar. but if the customer has role: user and comprobante: 0. I will show 4 option. This is my code where it is working only with role: user from mysql. Can anybody help me?

CODE:
$links = array();
$role = $this->Auth->user(‘role’);

    if($role == 'user') {
        $links = array(
            array(
                'title' => 'Detalle de visitas',
                'icon' => 'icon-bag',
                'controller' => 'dashboard',
                'action' => 'index',
                'sub' => array(
                    
                )
            ),
            array(
                'title' => 'Mis compras y pagos',
                'icon' => 'icon-doc',
                'controller' => 'dashboard',
                'action' => 'payments_invoices',
                'sub' => array(
                    
                )
            ),     
           array(
                'title' => 'Facturas y Recibos',
                'icon' => 'icon-doc',
                'controller' => 'dashboard',
                'action' => 'facturas_recibos',
                'sub' => array(
                    
                )
            ),
            array(
                'title' => 'Contacto',
                'icon' => 'icon-bubble',
                'controller' => 'dashboard',
                'action' => 'contact',
                'sub' => array(
                    
                )
            ),
            array(
                'title' => 'Mi cuenta',
                'icon' => 'icon-user',
                'controller' => 'users',
                'action' => 'profile',
                'sub' => array(
                    
                )
            ),
            array(
                'title' => 'Salir',
                'icon' => 'icon-logout',
                'controller' => 'users',
                'action' => 'logout',
                'sub' => array(
                    
                )
            ),
        );
    }

I would try to refactor your auth architecture a bit.

I would create a migration and change the role of the user if comprobante = 1 so we would have all the auth info in the users’s role:

  • role user, comprobante 1 --> change the role to member
  • role user, comprobante 0 --> leave the role as user

Then, each time a payment is done, I would update the role of the user to “member”. So now you can assign permissions per role.
There are many plugins available for doing this, check this one for example https://github.com/cakedc/users that would allow you to define permissions per controller/action and role, and use a Helper to display the link or not based on the current user’s permissions. See

Thanks,