RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
-</IfModule>
\ No newline at end of file
+ RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
+</IfModule>
--- /dev/null
+<?php
+use Migrations\AbstractMigration;
+
+class AddDigestHashToUsers 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('digest_hash', 'text', [
+ 'default' => null,
+ 'null' => true,
+ ]);
+ $table->update();
+ }
+}
public function beforeFilter(\Cake\Event\Event $event)
{
parent::beforeFilter($event);
-// $this->Auth->allow(['index', 'view']);
+ $this->Auth->allow(['index', 'view','lastAdded',"getProjectsById"]);
// $this->Auth->deny('edit');
}
}
- $review = $this->Softwares->Reviews->newEntity();
- if ($this->request->is('post') && !$this->request->is('json')) {
- $review = $this->Softwares->Reviews->patchEntity($review, $this->request->data);
- if ($this->Softwares->Reviews->save($review)) {
- $this->Flash->success(__('The review has been saved.'));
- return $this->redirect(['action' => 'index']);
- } else {
- debug ($review);
- $this->Flash->error(__('The review could not be saved. Please, try again.'));
- }
- $isAuthorized = $this->Auth->isAuthorized($this->Auth->user()); // La j'encule une mouche !!!
- $user = $this->Auth->user();
- $this->set(compact('review','user', 'isAuthorized', 'software'));
- $this->set('_serialize', ['review','user' ,'isAuthorized', 'software']);
- }else if ($this->request->is('post') && $this->request->is('json')) {
- $review = $this->Softwares->Reviews->patchEntity($review, $this->request->data);
- if ($this->Softwares->Reviews->save($review)) {
- $message = "Success";
-
- $isAuthorized = $this->Auth->isAuthorized($this->Auth->user());
- $user = $this->Auth->user();
- $this->set(compact('review','user', 'isAuthorized', 'software'));
- $this->set('_serialize', ['review','user' ,'isAuthorized', 'software']);
- } else {
- debug($review->errors());
- $message = "Error";
- }
- $this->set([
- 'message' => $message,
- 'review' => $review,
- '_serialize' => ['message', 'review','licenses']
- ]);
- }else{//Pour le template vant le post des données.
+ $review = $this->Softwares->Reviews->newEntity();
+ if ($this->request->is('post') && !$this->request->is('json')) {
+ $review = $this->Softwares->Reviews->patchEntity($review, $this->request->data);
+ if ($this->Softwares->Reviews->save($review)) {
+ $this->Flash->success(__('The review has been saved.'));
+ return $this->redirect(['action' => 'index']);
+ } else {
+ debug ($review);
+ $this->Flash->error(__('The review could not be saved. Please, try again.'));
+ }
+ $isAuthorized = $this->Auth->isAuthorized($this->Auth->user()); // La j'encule une mouche !!!
+ $user = $this->Auth->user();
+ $this->set(compact('review','user', 'isAuthorized', 'software'));
+ $this->set('_serialize', ['review','user' ,'isAuthorized', 'software']);
+ }else if ($this->request->is('post') && $this->request->is('json')) {
+ $review = $this->Softwares->Reviews->patchEntity($review, $this->request->data);
+ if ($this->Softwares->Reviews->save($review)) {
+ $message = "Success";
$isAuthorized = $this->Auth->isAuthorized($this->Auth->user());
$user = $this->Auth->user();
$this->set(compact('review','user', 'isAuthorized', 'software'));
$this->set('_serialize', ['review','user' ,'isAuthorized', 'software']);
+ } else {
+ debug($review->errors());
+ $message = "Error";
}
+ $this->set([
+ 'message' => $message,
+ 'review' => $review,
+ '_serialize' => ['message', 'review','licenses']
+ ]);
+ }else{//Pour le template vant le post des données.
+
+ $isAuthorized = $this->Auth->isAuthorized($this->Auth->user());
+ $user = $this->Auth->user();
+ $this->set(compact('review','user', 'isAuthorized', 'software'));
+ $this->set('_serialize', ['review','user' ,'isAuthorized', 'software']);
+ }
}
namespace App\Controller\Api\V1;
use App\Controller\AppController;
-use Cake\ORM\TableRegistry;
use Cake\Core\Configure;
+
/**
* Users Controller
*
return $this->redirect(['action' => 'index']);
}
-
-
- public function login()
- {
- if ($this->request->is('post')) {
- $user = $this->Auth->identify();
- if ($user) {
- $this->Auth->setUser($user);
- $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'));
- }
- }
-
- }
-
public function logout()
{
return $this->redirect($this->Auth->logout());
*/
public function isAuthorized($user)
{
- if ($this->Users->isAdministration($user['id'])) $this->Auth->allow('addReview');
+ if($this->Auth->user()){
+ return true;
+ }
return parent::isAuthorized($user);
}
*/
public function beforeFilter(\Cake\Event\Event $event)
{
+ $this->Auth->allow('add','digest');
parent::beforeFilter($event);
-
-
- $this->Auth->allow('login','isAdministration');
}
}
$this->loadComponent('Flash');
$this->loadComponent('Auth', [
- 'authorize' => ['Controller'],
- 'loginRedirect' => [
- 'controller' => 'Users',
- 'action' => 'login'
+ 'authorize' => 'Controller',
+ 'authenticate' => [
+ 'Digest' => [
+ 'fields' => ['username' => 'username', 'password' => 'digest_hash'],
+ 'userModel' => 'Users',
+ ],
],
- 'logoutRedirect' => [
- 'controller' => 'Users',
- 'action' => 'login',
- ],
- 'unauthorizedRedirect' => false,
+ 'realm' => env('SERVER_NAME'),
+ 'storage' => 'Memory',
+ 'unauthorizedRedirect' => false
]);
}
+
+
public function isAuthorized($user)
{
// Admin peuvent accéder à chaque action
public function beforeFilter(Event $event)
{
parent::beforeFilter($event);
+
+
// Allow users to register and logout.
// You should not add the "login" action to allow list. Doing so would
// cause problems with normal functioning of AuthComponent.
- $this->Auth->allow(['index','view','logout']);
+ $this->Auth->allow(['index','logout','digest']);
}
}
'*' => true,
'id' => false,
];
-
-
- protected function _setPassword($password)
- {
- return (new DefaultPasswordHasher)->hash($password);
- }
-
-
+
}
use Cake\ORM\Table;
use Cake\Validation\Validator;
+// User auth
+use Cake\Auth\DigestAuthenticate;
+use Cake\Auth\DefaultPasswordHasher;
+
+
/**
* Users Model
*
}
+ /**
+ * @param Event $event
+ * @return bool
+ */
+ public function beforeSave(Event $event)
+ {
+ $entity = $event->data['entity'];
+
+ // Make a password for digest auth.
+ $entity->digest_hash = DigestAuthenticate::password(
+ $entity->username,
+ $entity->password,
+ env('SERVER_NAME')
+ );
+
+ //Make a password for form auth
+ $entity->password = (new DefaultPasswordHasher)->hash($entity->password);
+
+ return true;
+ }
+
+
/**
* Returns TRUE if the user as know as Administration FALSE otherwise
* @param $userId user id Auth
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.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
+ RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</IfModule>
+
+