--- /dev/null
+<?php
+use Migrations\AbstractMigration;
+
+class AddActiveToUsers extends AbstractMigration
+{
+ /**
+ * Change Method.
+ *
+ * More information on this method is available here:
+ * http://docs.phinx.org/en/latest/migrations.html#the-change-method
+ * @return void
+ */
+ public function change()
+ {
+ $table = $this->table('users');
+ $table ->addColumn('active', 'boolean', [
+ 'default' => false,
+ 'null' => true
+ ]);
+ $table->update();
+ }
+}
Plugin::load('Migrations');
+
+Plugin::load('ADmad/JwtAuth');
Router::prefix('api/v1', function ($routes) {
Router::extensions(['json', 'xml']);
- $routes->resources('Softwares');
- // ONLY RIGHT ROUTES ARE ALLOWED
- $routes->connect('/request/*', ['controller' => 'Softwares', 'action' => 'view']);
$routes->connect('/connectorsList', ['controller' => 'Connectors', 'action' => 'connectors']);
$routes->fallbacks('DashedRoute');
});
public function login()
{
- $message = "test";
if ($this->request->is('post')) {
$user = $this->Auth->identify();
if ($user) {
$this->Auth->setUser($user);
- $message ="Success";
-
- }else {
- $message = __("Bad Username or bad password");
+ $this->set(compact('user'));
+ $this->set('_serialize', ['user']);
+ // return $this->redirect($this->Auth->redirectUrl());
+ }else{
+ $this->Flash->error(__('Invalid username or password, please try again'));
}
- $this->set([
- 'message' => $message,
- 'user' => $user,
- '_serialize' => ['message', 'user']
- ]);
- }else{
- $this->set([
- 'message' => $message,
- '_serialize' => ['message']
- ]);
}
}
public function isAuthorized($user)
{
- // Permet toutes les actions
- $this->Auth->allow();
return parent::isAuthorized($user);
}
'contain' => ['UserTypes']
];
+ $this->loadComponent('Auth', [
+ 'loginRedirect' => [
+ 'controller' => 'Users',
+ 'action' => 'index'
+ ],
+ 'logoutRedirect' => [
+ 'controller' => 'Softwares',
+ 'action' => 'index',
+ ]
+ ]);
+
+ }
+
+ /**
+ * @param Event $event
+ */
+ public function beforeFilter(\Cake\Event\Event $event)
+ {
+ parent::beforeFilter($event);
+ $this->Auth->allow();
}
}
* @var boolean
*/
public $haveErrors = false;
-
-
+
+
public $validator;
public $errors ;
-
-
+
+
use \Crud\Controller\ControllerTrait;
public $components = [
]
]
];
-
-
+
+
/**
* Initialization hook method.
*
public function initialize()
{
parent::initialize();
-
+
$this->loadComponent('RequestHandler');
-
+
$this->loadComponent('Flash');
-
- $this->loadComponent('Auth', [
- 'authenticate' => [
- 'Form' => [
- 'fields' => ['username' => 'username', 'password' => 'password']
- ]
- ]
- ]);
- }
-
- public function isAuthorized($user)
- {
- // Admin peuvent accéder à chaque action
- if (isset($user['role']) && ($user['role'] === 'admin')) {
- return true;
+
}
-
- // Par défaut refuser
- return true;
- }
-
-
+
+
/**
* Before render callback.
*
$this->RequestHandler->renderAs($this, 'json');
$this->set('_serialize', true);
}
-
+
$pagination = $this->request->paging[$this->modelClass];
if (empty($pagination)) {
return;
'limit' => $pagination['limit']
];
- $this->set('pagination', $paginationResponse);
-
$this->set('paging',$this->request->params['paging']);
-
-// $this->RequestHandler->renderAs($this, 'json');
-//
-// $this->set('_serialize', true);
-//
-
}
-
+
/**
- *
+ *
* @param Event $event
*/
public function beforeFilter(Event $event) {
- $this->Auth->allow();
parent::beforeFilter($event);
}
-
+
}
return $query;
}
+ public function findAuth(\Cake\ORM\Query $query, array $options)
+ {
+ $query
+ ->select(['id', 'username', 'password'])
+ ->where(['Users.active' => true]);
+
+ return $query;
+ }
+
/**
* Default validation rules.
*