2012-03-15 15:06:45 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Application level Controller
|
|
|
|
*
|
|
|
|
* This file is application-wide controller file. You can put all
|
|
|
|
* application-wide controller-related methods here.
|
|
|
|
*
|
|
|
|
* PHP 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
|
|
|
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
|
|
|
* @package app.Controller
|
|
|
|
* @since CakePHP(tm) v 0.2.9
|
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
|
|
*/
|
|
|
|
|
|
|
|
App::uses('Controller', 'Controller');
|
|
|
|
App::uses('Sanitize', 'Utility');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Application Controller
|
|
|
|
*
|
|
|
|
* Add your application-wide methods in the class below, your controllers
|
|
|
|
* will inherit them.
|
|
|
|
*
|
|
|
|
* @package app.Controller
|
|
|
|
* @link http://book.cakephp.org/2.0/en/controllers.html#the-app-controller
|
|
|
|
*/
|
|
|
|
class AppController extends Controller {
|
2012-03-26 19:56:44 +02:00
|
|
|
|
2012-03-15 15:06:45 +01:00
|
|
|
public $components = array(
|
|
|
|
'Session',
|
|
|
|
'Auth' => array(
|
|
|
|
'authenticate' => array(
|
|
|
|
'Form' => array(
|
|
|
|
'fields' => array('username' => 'email')
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'loginRedirect' => array('controller' => 'users', 'action' => 'routeafterlogin'),
|
|
|
|
'logoutRedirect' => array('controller' => 'users', 'action' => 'login'),
|
|
|
|
'authorize' => array('Controller') // Added this line
|
|
|
|
)
|
|
|
|
);
|
2012-03-26 19:56:44 +02:00
|
|
|
|
|
|
|
|
2012-03-15 15:06:45 +01:00
|
|
|
public function isAuthorized($user) {
|
2012-03-27 09:31:41 +02:00
|
|
|
if (self::_isAdmin()) {
|
2012-03-20 14:57:52 +01:00
|
|
|
return true; // admin can access every action on every controller
|
2012-03-15 15:06:45 +01:00
|
|
|
}
|
|
|
|
return false; // The rest don't
|
|
|
|
}
|
2012-03-26 19:56:44 +02:00
|
|
|
|
2012-03-15 15:06:45 +01:00
|
|
|
function beforeFilter() {
|
|
|
|
|
|
|
|
}
|
2012-03-26 19:56:44 +02:00
|
|
|
|
|
|
|
|
2012-03-15 15:06:45 +01:00
|
|
|
/**
|
2012-03-26 19:56:44 +02:00
|
|
|
* Convert an array to the same array but with the values also as index instead of an interface_exists
|
|
|
|
*/
|
2012-03-15 15:06:45 +01:00
|
|
|
function _arrayToValuesIndexArray($old_array) {
|
|
|
|
$new_array = Array();
|
|
|
|
foreach ($old_array as $value)
|
|
|
|
$new_array[$value] = $value;
|
|
|
|
return $new_array;
|
|
|
|
}
|
2012-03-26 19:56:44 +02:00
|
|
|
|
2012-03-15 15:06:45 +01:00
|
|
|
/**
|
2012-03-26 19:56:44 +02:00
|
|
|
* checks if the currently logged user is an administrator
|
|
|
|
*/
|
2012-03-15 15:06:45 +01:00
|
|
|
public function _isAdmin() {
|
2012-03-27 09:31:41 +02:00
|
|
|
$org = $this->Auth->user('org');
|
|
|
|
if (isset($org) && $org === 'ADMIN') {
|
2012-03-15 15:06:45 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Refreshes the Auth session with new/updated data
|
2012-03-26 19:56:44 +02:00
|
|
|
* @return void
|
2012-03-15 15:06:45 +01:00
|
|
|
*/
|
|
|
|
function _refreshAuth() {
|
|
|
|
if (isset($this->User)) {
|
|
|
|
$user = $this->User->read(false, $this->Auth->user('id'));
|
|
|
|
} else {
|
|
|
|
$user= ClassRegistry::init('User')->findById($this->Auth->user('id'));
|
|
|
|
}
|
|
|
|
$this->Auth->login($user['User']);
|
|
|
|
}
|
|
|
|
|
2012-03-26 19:56:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the missing fields from v0.1 to v0.2 of CyDefSIG
|
2012-03-26 20:25:45 +02:00
|
|
|
* First you will need to manually update the database to the new schema.
|
|
|
|
* Then run this function by setting debug = 1 (or more) and call /events/migrate
|
2012-03-26 19:56:44 +02:00
|
|
|
*/
|
2012-03-26 20:25:45 +02:00
|
|
|
function migrate() {
|
|
|
|
if (Configure::read('debug') == 0) throw new NotFoundException();
|
2012-03-26 19:56:44 +02:00
|
|
|
// generate uuids for events who have no uuid
|
|
|
|
$this->loadModel('Event');
|
2012-03-26 20:25:45 +02:00
|
|
|
$params = array(
|
|
|
|
'conditions' => array('Event.uuid' => ''),
|
|
|
|
'recursive' => 0,
|
|
|
|
'fields' => array('Event.id'),
|
|
|
|
);
|
|
|
|
$events = $this->Event->find('all', $params);
|
|
|
|
|
|
|
|
echo '<p>Generating UUID for events: ';
|
|
|
|
foreach ($events as $event) {
|
|
|
|
$this->Event->id = $event['Event']['id'];
|
|
|
|
$this->Event->saveField('uuid', String::uuid());
|
|
|
|
echo $event['Event']['id'].' ';
|
|
|
|
}
|
|
|
|
echo "</p>";
|
2012-03-26 19:56:44 +02:00
|
|
|
// generate uuids for attributes who have no uuid
|
|
|
|
$this->loadModel('Attribute');
|
2012-03-26 20:25:45 +02:00
|
|
|
$params = array(
|
|
|
|
'conditions' => array('Attribute.uuid' => ''),
|
|
|
|
'recursive' => 0,
|
|
|
|
'fields' => array('Attribute.id'),
|
|
|
|
);
|
|
|
|
$attributes = $this->Attribute->find('all', $params);
|
|
|
|
echo '<p>Generating UUID for attributes: ';
|
|
|
|
foreach ($attributes as $attribute) {
|
|
|
|
$this->Attribute->id = $attribute['Attribute']['id'];
|
|
|
|
$this->Attribute->saveField('uuid', String::uuid());
|
|
|
|
echo $attribute['Attribute']['id'].' ';
|
|
|
|
}
|
|
|
|
echo "</p>";
|
2012-03-26 19:56:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-03-15 15:06:45 +01:00
|
|
|
}
|