namespace App\Controller\Api\V1;
use App\Controller\AppController;
-use Cake\ORM\TableRegistry;
use Cake\Core\Configure;
+
/**
* Users Controller
*
*/
public function index()
{
- $users = $this->Users->find("all")
- ->where(["UserTypes.name = " => "Administration" ])
- ;
- $this->set('users', $this->paginate($users));
- $this->set('_serialize', ['users','paging']);
+ try {
+ $users = $this->Users->find("all")->contain(["UserTypes"])
+ ->where(["UserTypes.name = " => "Administration" ])
+ ;
+ $this->set([
+ 'message' => "Success",
+ 'users' => $this->paginate($users),
+ '_serialize' => ['message', 'users']
+ ]);
+ }catch(Exception $e){
+
+ }
}
/**
'photo',
'description'
]
- ]
+ ],
],
"Providerforsoftwares" =>[
'strategy' => 'select',
'photo',
'description'
]
- ]
+ ],
],
]
]);
if ($this->request->is('post') && $this->request->is('json')) {
$user = $this->Users->patchEntity($user, $this->request->data);
if ($this->Users->save($user) ) {
- $message = "success";
+ $message = "Success";
} else {
$message = "Error";
}
$this->set(compact('user', 'userTypes'/*, 'relationshipsSoftwares', 'relationships'*/));
$this->set('_serialize', ['user']);
}else {//Pour le template avans d'avoir poster les données.
+
+
$userTypes = $this->Users->UserTypes->find('list', ['limit' => 200]);
+
$this->set(compact('user', 'userTypes'/*, 'relationshipsSoftwares', 'relationships'*/));
- $this->set('_serialize', ['user']);
+ $this->set('_serialize', ['user','userTypes']);
}
}
$user = $this->Users->patchEntity($user, $this->request->data);
if ($this->Users->save($user)) {
$this->Flash->success(__('The user has been saved.'));
- return $this->redirect(['action' => 'index']);
+ $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The user could not be saved. Please, try again.'));
}
}
}
- /**
- *
- */
- public function isAdministration (){
- try {
- $user = $this->Users->get($this->request->query["id"], [
- 'contain' => ['UserTypes',]
- ]);
-
- $this->set([
- 'message' => "Success",
- 'user' => $user,
- '_serialize' => ['message', 'user']
- ]);
- }catch(Exception $e){
-
- }
- }
-
- public function administrationUsers () {
- try {
- $users = $this->Users->find("all")->contain(["UserTypes"])
- ->where(["UserTypes.name = " => "Administration" ])
- ;
- $this->set([
- 'message' => "Success",
- 'users' => $this->paginate($users),
- '_serialize' => ['message', 'users']
- ]);
- }catch(Exception $e){
-
- }
- }
-
public function servicesproviderUsers(){
try {
$users = $this->Users->find("all")->contain(["UserTypes"])
'queryBuilder' => function ($q) {
return $q->order(['Softwares.softwarename' =>'ASC']);
},
+ 'UserTypes',
'Softwares' => [
'fields' => [
'id',
$user = $this->Users->get($id,
["contain" =>
[
+ 'UserTypes',
'Backedsoftwares' =>
[
'strategy' => 'select',
$user = $this->Users->get($id,
["contain" =>
[
+ 'UserTypes',
'Createdsoftwares' =>
[
'strategy' => 'select',
$user = $this->Users->get($id,
["contain" =>
[
+ 'UserTypes',
'Contributionssoftwares' =>
[
'strategy' => 'select',
$user = $this->Users->get($id,
["contain" =>
[
+ 'UserTypes',
'Providerforsoftwares' =>
[
'strategy' => 'select',
- public function login()
+ public function register()
{
- $message = "test";
if ($this->request->is('post')) {
- $user = $this->Auth->identify();
+ $user = $this->Auth->user();
if ($user) {
- $this->Auth->setUser($user);
- $message ="Success";
-
- }else {
- $message = __("Bad Username or bad password");
+ $this->set('digest', $_SERVER["PHP_AUTH_DIGEST"]);
+ }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)
{
+ if ($this->Auth->identify()){
+ return true ;
+ }
+
- // Permet toutes les actions
- $this->Auth->allow();
+ //If user is auth
+ if ($this->request->param('action') === 'register'){
+
+ if ($user){
+
+ return true;
+ }
+ }
return parent::isAuthorized($user);
}
public function initialize(){
-
-
parent::initialize();
+ $this->paginate = [
+ 'limit' => Configure::read('LIMIT'),
+ 'order' => [
+ 'Users.username' => Configure::read('ORDER'),
+ ],
+ 'contain' => ['UserTypes']
+ ];
+ }
- $this->paginate = [
- 'limit' => Configure::read('LIMIT'),
- 'order' => [
- 'Users.username' => Configure::read('ORDER'),
- ],
- 'contain' => ['UserTypes']
- ];
-
+ /**
+ * @param Event $event
+ */
+ public function beforeFilter(\Cake\Event\Event $event)
+ {
+ $this->Auth->allow('servicesproviderUsers');
+ $this->Auth->deny('delete');
+ parent::beforeFilter($event);
}
}