how to allow home page to access without login and when any userlogin restrict access to home page to for that user in cakephp 3

69 Views Asked by At

I am trying to write code in such a manner that, when anyone logs in to my sight with user role=merchant he will not allow accessing my home page and when anyone login with user role=customer then he will allow accessing the home page, rather than that anyone without a login can visit my home page

1

There are 1 best solutions below

0
Sehdev On

You can define your rule in isAuthorized action in /src/Controller/AppController.php

// src/Controller/AppController.php



 public function isAuthorized($user)
    {
// Assuming home function as your home page
        if ($this->request->getParam('action') == 'home' && $user['role'] == 'customer' ) {
            return true;
        }
       return false;
    }

Cakephp -> Authentication and Authorization -> Authorization (who’s allowed to access what)