Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
app
<?php
namespace App\Controller\Api\V1;
use Cake\Controller\Controller;
class AppController extends Controller
{
// public $components = [
// 'Acl' => [
// 'className' => 'Acl.Acl'
// ]
// ];
public function initialize()
{
parent::initialize();
$this->loadComponent('RequestHandler');
$this->loadComponent('Flash');
$this->loadComponent('Crud.Crud', [
'actions' => [
'Crud.Index',
'Crud.View',
'Crud.Add',
'Crud.Edit',
'Crud.Delete'
],
'listeners' => [
// 'Crud.Api',
'Crud.ApiPagination',
'Crud.ApiQueryLog',
'Crud.Search',
]
]);
if ($this->request->getParam('controller') == 'Users') {
$this->Crud->addListener('Crud.Api');
} else {
$this->Crud->addListener('Crud.JsonApi');
}
$this->loadComponent('Auth', [
'storage' => 'Memory',
'authenticate' => [
'Form' => [
'scope' => ['Users.active' => 1]
],
'ADmad/JwtAuth.Jwt' => [
'parameter' => 'token',
'userModel' => 'Users',
//'scope' => ['Users.active' => 1],
'fields' => [
'username' => 'id'
],
'queryDatasource' => true
]
],
'unauthorizedRedirect' => false,
'checkAuthIn' => 'Controller.initialize'
]);
// $this->loadComponent('Auth', [
// 'authorize' => [
// 'Acl.Actions' => ['actionPath' => 'controllers/']
// ],
// 'loginAction' => [
// 'plugin' => false,
// 'controller' => 'Users',
// 'action' => 'login'
// ],
// 'loginRedirect' => [
// 'plugin' => false,
// 'controller' => 'Customers',
// 'action' => 'index'
// ],
// 'logoutRedirect' => [
// 'plugin' => false,
// 'controller' => 'Users',
// 'action' => 'login'
// ],
// 'unauthorizedRedirect' => [
// 'controller' => 'Users',
// 'action' => 'login',
// 'prefix' => false
// ],
// 'authError' => 'You are not authorized to access that location.',
// 'flash' => [
// 'element' => 'error'
// ]
// ]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment