1. Go to this page and download the library: Download ccasanovas/cake-cognito library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ccasanovas / cake-cognito example snippets
'CognitoSDK' => [
'AccessKeys' => [
'id' => 'NSWPXE30F49XAOF',
'secret' => 'QIQNxRO2425bb040e4adc8cc02fae05063c3c'
],
'UserPool' => [
'id' => 'us-east-2_rjaob1HaR',
],
'IdentityProviderClient' => [
'settings' => [], //https://docs.aws.amazon.com/sdkforruby/api/Aws/CognitoIdentityProvider/Client.html#initialize-instance_method
],
],
'ApiUsers' => [
/* available user roles */
'roles' => [
'user' => __d('Ccasanovas/CognitoSDK', 'API User'),
],
/* the max amount of errors alloweds before the validation process of the imported data is halted */
'import_max_errors' => 10,
/* the limit of accepted rows in the importing CSV data */
'import_max_rows' => 500,
]
//archivo: src/Model/Table/ApiUsersTable.php
namespace App\Model\Table;
use Ccasanovas\CognitoSDK\Model\Entity\ApiUser;
use Ccasanovas\CognitoSDK\Model\Table\ApiUsersTable as AwsApiUsersTable;
class ApiUsersTable extends AwsApiUsersTable
{
//esto solo es necesario si no se va a extender la Entidad
protected $_entityClass = 'Ccasanovas\CognitoSDK\Model\Entity\ApiUser';
public function initialize(array $config)
{
parent::initialize($config);
//cambiando la tabla de usuarioa administradores
$this->association('Creators')->className('AppUsers');
$this->association('Modifiers')->className('AppUsers');
//agregar nuevas asociaciones aca
$this->belongsToMany('FunctionalUnits', [
'through' => 'ApiUsersFunctionalUnits',
'saveStrategy' =>'append',
]);
//y podemos facilmente reconfigurar el search cambiando estos valores
$this->searchQueryFields = [
'ApiUsers.aws_cognito_username',
'ApiUsers.email',
'ApiUsers.phone',
'ApiUsers.first_name',
'ApiUsers.last_name',
];
}
//extendiendo la validación por defecto
public function validationDefault(Validator $validator)
{
$validator = parent::validationDefault($validator);
//se puede remover la validacion de un campo si no se usa
$validator->remove('role');
//y agregar campos nuevos
$validator
->scalar('phone')
->allowEmpty('phone');
return $validator;
}
}
//archivo: src/Controller/ApiUsersController.php
namespace App\Controller;
use Ccasanovas\CognitoSDK\Controller\ApiUsersController as AwsApiUsersController;
use App\Model\Table\ApiUsersTable;
class ApiUsersController extends AwsApiUsersController
{
//aca se pueden agregar nuevas acciones o reemplazar las existentes
//por ejemplo el index:
public function index()
{
$this->paginate['contain'] = ['PointsOfSale'];
$this->set('api_users', $this->paginate('ApiUsers'));
$this->set('_serialize', ['api_users']);
}
}