Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save timeelementopuro/5f87cabac63def6d50a83c551e04d235 to your computer and use it in GitHub Desktop.
Save timeelementopuro/5f87cabac63def6d50a83c551e04d235 to your computer and use it in GitHub Desktop.
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