Merge branch 'master' of github.com:agourd/dev-fsociety
Conflicts: src/Template/Layout/default.ctp
This commit is contained in:
config
src
Controller
Template
@ -47,7 +47,7 @@ Router::scope('/', function ($routes) {
|
||||
* its action called 'display', and we pass a param to select the view file
|
||||
* to use (in this case, src/Template/Pages/home.ctp)...
|
||||
*/
|
||||
$routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']);
|
||||
$routes->connect('/', ['controller' => 'Homes', 'action' => 'index']);
|
||||
|
||||
/**
|
||||
* ...and connect the rest of 'Pages' controller's URLs.
|
||||
|
@ -3,7 +3,6 @@ namespace App\Controller;
|
||||
|
||||
use App\Controller\AppController;
|
||||
use Cake\Event\Event;
|
||||
|
||||
/**
|
||||
* Articles Controller
|
||||
*
|
||||
@ -12,18 +11,23 @@ use Cake\Event\Event;
|
||||
class ArticlesController extends AppController
|
||||
{
|
||||
|
||||
/**
|
||||
* beforeFilter method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
public function beforeFilter(Event $event)
|
||||
{
|
||||
parent::beforeFilter($event);
|
||||
$this->Auth->allow(['index', 'view']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Index method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function beforeFilter(Event $event)
|
||||
{
|
||||
parent::beforeFilter($event);
|
||||
|
||||
$this->Auth->allow(['index', 'view']);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->paginate = [
|
||||
@ -59,6 +63,7 @@ class ArticlesController extends AppController
|
||||
$article = $this->Articles->newEntity();
|
||||
if ($this->request->is('post')) {
|
||||
$article = $this->Articles->patchEntity($article, $this->request->data);
|
||||
$article->user_id = $this->Auth->user('id');
|
||||
if ($this->Articles->save($article)) {
|
||||
$this->Flash->success(__('The article has been saved.'));
|
||||
return $this->redirect(['action' => 'index']);
|
||||
@ -66,7 +71,6 @@ class ArticlesController extends AppController
|
||||
$this->Flash->error(__('The article could not be saved. Please, try again.'));
|
||||
}
|
||||
}
|
||||
$users = $this->Articles->Users->find('list', ['limit' => 200]);
|
||||
$this->set(compact('article', 'users'));
|
||||
$this->set('_serialize', ['article']);
|
||||
}
|
||||
@ -115,4 +119,28 @@ class ArticlesController extends AppController
|
||||
}
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
|
||||
/**
|
||||
* isAuthorized method
|
||||
*
|
||||
* @param $user
|
||||
* @return True or False
|
||||
*/
|
||||
public function isAuthorized($user)
|
||||
{
|
||||
// All registered users can add articles
|
||||
if ($this->request->action === 'add') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// The owner of an article can edit and delete it
|
||||
if (in_array($this->request->action, ['edit', 'delete'])) {
|
||||
$articleId = (int)$this->request->params['pass'][0];
|
||||
if ($this->Articles->isOwnedBy($articleId, $user['id'])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return parent::isAuthorized($user);
|
||||
}
|
||||
}
|
||||
|
@ -4,15 +4,41 @@ namespace App\Controller;
|
||||
use App\Controller\AppController;
|
||||
|
||||
/**
|
||||
* Users Controller
|
||||
* Homes Controller
|
||||
*
|
||||
* @property \App\Model\Table\UsersTable $Users
|
||||
*/
|
||||
|
||||
class HomesController extends AppController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
|
||||
$this->loadModel('Crisis');
|
||||
$this->loadModel('Articles');
|
||||
|
||||
$spottedCrises = $this->Crisis->find()
|
||||
->where(['state' => 'spotted']);
|
||||
if($spottedCrises->count() != 0)
|
||||
{
|
||||
$home_type = 'spotted';
|
||||
}
|
||||
|
||||
$verifiedCrises = $this->Crisis->find()
|
||||
->where(['state' => 'verified']);
|
||||
if($verifiedCrises->count() != 0)
|
||||
{
|
||||
$home_type = 'active';
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$home_type = 'none';
|
||||
}
|
||||
|
||||
$articles = $this->Articles->find('all')
|
||||
->limit(5)->orderBy('created');
|
||||
|
||||
$this->set(compact('spottedCrises', 'verifiedCrises', 'articles'));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,25 +15,19 @@ class UsersController extends AppController
|
||||
public function beforeFilter(Event $event)
|
||||
{
|
||||
parent::beforeFilter($event);
|
||||
|
||||
$this->Auth->allow(['logout']);
|
||||
$this->Auth->allow(['logout','add','view','index']);
|
||||
}
|
||||
|
||||
public function login()
|
||||
{
|
||||
if($this->request->is('post'))
|
||||
{
|
||||
$user = $this->Auth->identify();
|
||||
|
||||
if($user)
|
||||
{
|
||||
$this->set('authUser', $this->Auth->user());
|
||||
$this->Auth->setUser($user);
|
||||
return $this->redirect($this->Auth->redirectUrl());
|
||||
}
|
||||
|
||||
$this->Flash->error(__("Nom d'utilisateur et / ou mot de passe incorrect(s), essayez à nouveau."));
|
||||
if ($this->request->is('post')) {
|
||||
$user = $this->Auth->identify();
|
||||
if ($user) {
|
||||
$this->Auth->setUser($user);
|
||||
return $this->redirect($this->Auth->redirectUrl());
|
||||
}
|
||||
$this->Flash->error(__('Invalid username or password, try again'));
|
||||
}
|
||||
}
|
||||
|
||||
public function logout()
|
||||
|
@ -13,7 +13,7 @@
|
||||
<?php
|
||||
echo $this->Form->input('title');
|
||||
echo $this->Form->input('body');
|
||||
echo $this->Form->input('user_id', ['options' => $users]);
|
||||
// echo $this->Form->input('user_id', ['options' => $users]);
|
||||
echo $this->Form->input('category');
|
||||
?>
|
||||
</fieldset>
|
||||
|
@ -19,7 +19,7 @@
|
||||
<?php
|
||||
echo $this->Form->input('title');
|
||||
echo $this->Form->input('body');
|
||||
echo $this->Form->input('user_id', ['options' => $users]);
|
||||
// echo $this->Form->input('user_id', ['options' => $users]);
|
||||
echo $this->Form->input('category');
|
||||
?>
|
||||
</fieldset>
|
||||
|
@ -1,7 +1,12 @@
|
||||
<?php
|
||||
$class = 'message';
|
||||
|
||||
$class = '';
|
||||
if (!empty($params['class'])) {
|
||||
$class .= ' ' . $params['class'];
|
||||
}
|
||||
?>
|
||||
<div class="<?= h($class) ?>"><?= h($message) ?></div>
|
||||
|
||||
<div data-alert class="alert-box <?= h($class) ?>" tabindex="0" aria-live="assertive" role="alertdialog">
|
||||
<?= h($message) ?>
|
||||
<button tabindex="0" class="close" aria-label="Close Alert">×</button>
|
||||
</div>
|
||||
|
@ -86,11 +86,8 @@
|
||||
<div class="small-12 columns">
|
||||
<p class="slogan">/dev/fsociety</p>
|
||||
<p class="links">
|
||||
|
||||
<a href="#"><?= $this->Html->link(__('Home'), ['controller'=>'Home', 'action' => 'index']) ?></a>
|
||||
<a href="#"><?= $this->Html->link(__('About us'), ['controller'=>'Home', 'action' => 'index'])?></a>
|
||||
<a href="#"><?= $this->Html->link(__('Contact our team'), ['controller'=>'Home', 'action' => 'index'])?></a>
|
||||
|
||||
<a href="http://book.cakephp.org/3.0/">Documentation</a>
|
||||
<a href="http://api.cakephp.org/3.0/">API</a>
|
||||
</p>
|
||||
<p class="copywrite">Fsociety all rights reserved © 2015</p>
|
||||
</div>
|
||||
@ -101,10 +98,12 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Foundation (+jquery) scripts -->
|
||||
<?= $this->Html->script("vendor/jquery.min.js") ?>
|
||||
<?= $this->Html->script("vendor/what-input.min.js") ?>
|
||||
|
||||
<?= $this->Html->script("foundation/foundation.js") ?>
|
||||
<?= $this->Html->script("foundation/foundation.alert.js") ?>
|
||||
<?= $this->Html->script("foundation/foundation.topbar.js") ?>
|
||||
|
||||
<!-- Own script -->
|
||||
|
Reference in New Issue
Block a user