jdmaymeow/cake-auth

This package is abandoned and no longer maintained. No replacement package was suggested.
There is no license information available for the latest version (v1.2.7) of this package.

CakeAuth plugin for CakePHP

Installs: 76

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:cakephp-plugin

v1.2.7 2017-03-05 17:46 UTC

This package is not auto-updated.

Last update: 2021-11-11 17:13:15 UTC


README

This is part of Code Advent 2016

Installation

You can install this plugin into your CakePHP application using composer.

The recommended way to install composer packages is:

composer require jdmaymeow/cake-auth

Load plugin

bin/cake plugin load CakeAuth -r

Configure

To AppController Initialize add

$this->loadComponent('Auth', [
            'authorize' => ['Controller'], // Added this line
            'loginRedirect' => [
                'controller' => 'Links',
                'action' => 'index'
            ],
            'logoutRedirect' => [
                'controller' => 'Users',
                'action' => 'login',
                'home'
            ]
        ]);

Add after initialize function into main APpControler

public function beforeFilter(Event $event)
    {
        $this->Auth->allow(['index', 'view', 'display']);
    }

public function isAuthorized($user)
    {
        // Admin can access every action
        if (isset($user['role']) && $user['role'] === 'admin') {
            return true;
        }

        // Default deny
        return false;
    }

Standard Configuration

Allowed actions

Role Login Logout Index Add Edit View Delete Display
Author Yes Yes Yes Yes No Yes No Yes
Admin Yes Yes Yes Yes Yes Yes Yes Yes