コード例 #1
0
 function beforeFilter()
 {
     if (!CakeSession::started()) {
         CakeSession::start();
     }
     $this->Auth->allow();
 }
コード例 #2
0
ファイル: TrackableBehavior.php プロジェクト: saydulk/croogo
 /**
  * Fill the created_by and updated_by fields
  *
  * Note: Since shells do not have Sessions, created_by/updated_by fields
  * will not be populated. If a shell needs to populate these fields, you
  * can simulate a logged in user by setting `Trackable.Auth` config:
  *
  *   Configure::write('Trackable.User', array('id' => 1));
  *
  * Note that value stored in this variable overrides session data.
  */
 public function beforeSave(Model $model, $options = array())
 {
     if (!$this->_hasTrackableFields($model)) {
         return true;
     }
     $config = $this->settings[$model->alias];
     $User = ClassRegistry::init($config['userModel']);
     $userAlias = $User->alias;
     $userPk = $User->primaryKey;
     $user = Configure::read('Trackable.Auth.User');
     if (!$user && CakeSession::started()) {
         $user = AuthComponent::user();
     }
     if ($user && array_key_exists($userPk, $user)) {
         $userId = $user[$userPk];
     }
     if (empty($user) || empty($userId)) {
         return true;
     }
     $alias = $model->alias;
     $createdByField = $config['fields']['created_by'];
     $updatedByField = $config['fields']['updated_by'];
     if (empty($model->data[$alias][$createdByField])) {
         if (!$model->exists()) {
             $model->data[$alias][$createdByField] = $user[$userPk];
         }
     }
     $model->data[$alias][$updatedByField] = $userId;
     if (!empty($model->whitelist)) {
         $model->whitelist[] = $createdByField;
         $model->whitelist[] = $updatedByField;
     }
     return true;
 }
コード例 #3
0
 /**
  * tearDown
  *
  * @return void
  */
 public function tearDown()
 {
     parent::tearDown();
     if (CakeSession::started()) {
         CakeSession::clear();
         CakeSession::destroy();
     }
     ClassRegistry::flush();
 }
コード例 #4
0
 /**
  * setUp method
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $controller = null;
     $this->View = new View($controller);
     $this->Flash = new FlashHelper($this->View);
     if (!CakeSession::started()) {
         CakeSession::start();
     }
     CakeSession::write(array('Flash' => array('flash' => array('key' => 'flash', 'message' => 'This is a calling', 'element' => 'Flash/default', 'params' => array()), 'notification' => array('key' => 'notification', 'message' => 'Broadcast message testing', 'element' => 'flash_helper', 'params' => array('title' => 'Notice!', 'name' => 'Alert!')), 'classy' => array('key' => 'classy', 'message' => 'Recorded', 'element' => 'flash_classy', 'params' => array()))));
 }
コード例 #5
0
ファイル: session.test.php プロジェクト: robotarmy/Phog
 /**
  * setUp method
  *
  * @access public
  * @return void
  */
 function setUp()
 {
     parent::setUp();
     $controller = null;
     $this->View = new View($controller);
     $this->Session = new SessionHelper($this->View);
     if (!CakeSession::started()) {
         CakeSession::start();
     }
     $_SESSION = array('test' => 'info', 'Message' => array('flash' => array('element' => 'default', 'params' => array(), 'message' => 'This is a calling'), 'notification' => array('element' => 'session_helper', 'params' => array('title' => 'Notice!', 'name' => 'Alert!'), 'message' => 'This is a test of the emergency broadcasting system'), 'classy' => array('element' => 'default', 'params' => array('class' => 'positive'), 'message' => 'Recorded'), 'bare' => array('element' => null, 'message' => 'Bare message', 'params' => array())), 'Deeply' => array('nested' => array('key' => 'value')));
 }
コード例 #6
0
ファイル: RolUser.php プロジェクト: ristorantino/users
 /**
  * Sets up the configuration for the model, and loads databse from Multi Tenant Site
  *
  * @param Model $model Model using this behavior.
  * @param array $config Configuration options.
  * @return void
  */
 public function __construct($id = false, $table = null, $ds = null)
 {
     // usar el correspondiente al tenant
     //debug( Router::$_requests );
     if (CakeSession::started()) {
         $currentTenant = MtSites::getSiteName();
         if ($currentTenant) {
             // listar sources actuales
             $sources = ConnectionManager::enumConnectionObjects();
             //copiar del default
             $tenantConf = $sources['default'];
             // colocar el nombre de la base de datos
             $tenantConf['database'] = $tenantConf['database'] . "_" . $currentTenant;
             // crear la conexion con la bd
             $confName = 'tenant_' . $currentTenant;
             ConnectionManager::create($confName, $tenantConf);
             // usar tenant para este model
             $this->useDbConfig = $confName;
         }
     }
     // ahora construir el Model
     parent::__construct($id, $table, $ds);
 }
コード例 #7
0
 /**
  * Returns a bool, whether or not the session has been started.
  *
  * @return boolean
  */
 public function started()
 {
     return CakeSession::started();
 }
コード例 #8
0
ファイル: session.php プロジェクト: laiello/myopensources
 /**
  * Determine if Session has been started
  * and attempt to start it if not
  *
  * @return boolean true if Session is already started, false if
  * Session could not be started
  * @access public
  */
 function __start()
 {
     if (!parent::started()) {
         parent::start();
     }
     return true;
 }
コード例 #9
0
ファイル: I18n.php プロジェクト: manzapanza/cakephp-api-utils
 /**
  * Used by the translation functions in basics.php
  * Returns a translated string based on current language and translation files stored in locale folder
  *
  * @param string $singular String to translate
  * @param string $plural Plural string (if any)
  * @param string $domain Domain The domain of the translation. Domains are often used by plugin translations.
  *    If null, the default domain will be used.
  * @param string $category Category The integer value of the category to use.
  * @param integer $count Count Count is used with $plural to choose the correct plural form.
  * @param string $language Language to translate string to.
  *    If null it checks for language in session followed by Config.language configuration variable.
  * @return string translated string.
  * @throws CakeException When '' is provided as a domain.
  */
 public static function translate($singular, $plural = null, $domain = null, $category = 6, $count = null, $language = null)
 {
     $_this = I18n::getInstance();
     if (strpos($singular, "\r\n") !== false) {
         $singular = str_replace("\r\n", "\n", $singular);
     }
     if ($plural !== null && strpos($plural, "\r\n") !== false) {
         $plural = str_replace("\r\n", "\n", $plural);
     }
     if (is_numeric($category)) {
         $_this->category = $_this->_categories[$category];
     }
     if (empty($language)) {
         if (CakeSession::started()) {
             $language = CakeSession::read('Config.language');
         }
         if (empty($language)) {
             $language = Configure::read('Config.language');
         }
     }
     if ($_this->_lang && $_this->_lang !== $language || !$_this->_lang) {
         $lang = $_this->l10n->get($language);
         $_this->_lang = $lang;
     }
     if ($domain === null) {
         $domain = self::$defaultDomain;
     }
     if ($domain === '') {
         throw new CakeException(__d('cake_dev', 'You cannot use "" as a domain.'));
     }
     $_this->domain = $domain . '_' . $_this->l10n->lang;
     if (!isset($_this->_domains[$domain][$_this->_lang])) {
         $_this->_domains[$domain][$_this->_lang] = Cache::read($_this->domain, '_cake_core_');
     }
     if (!isset($_this->_domains[$domain][$_this->_lang][$_this->category])) {
         $_this->_bindTextDomain($domain);
         Cache::write($_this->domain, $_this->_domains[$domain][$_this->_lang], '_cake_core_');
     }
     if ($_this->category === 'LC_TIME') {
         return $_this->_translateTime($singular, $domain);
     }
     if (!isset($count)) {
         $plurals = 0;
     } elseif (!empty($_this->_domains[$domain][$_this->_lang][$_this->category]["%plural-c"]) && $_this->_noLocale === false) {
         $header = $_this->_domains[$domain][$_this->_lang][$_this->category]["%plural-c"];
         $plurals = $_this->_pluralGuess($header, $count);
     } else {
         if ($count != 1) {
             $plurals = 1;
         } else {
             $plurals = 0;
         }
     }
     if (!empty($_this->_domains[$domain][$_this->_lang][$_this->category][$singular])) {
         if (($trans = $_this->_domains[$domain][$_this->_lang][$_this->category][$singular]) || $plurals && ($trans = $_this->_domains[$domain][$_this->_lang][$_this->category][$plural])) {
             if (is_array($trans)) {
                 if (isset($trans[$plurals])) {
                     $trans = $trans[$plurals];
                 } else {
                     trigger_error(__d('cake_dev', 'Missing plural form translation for "%s" in "%s" domain, "%s" locale. ' . ' Check your po file for correct plurals and valid Plural-Forms header.', $singular, $domain, $_this->_lang), E_USER_WARNING);
                     $trans = $trans[0];
                 }
             }
             if (strlen($trans)) {
                 return $trans;
             }
         }
     }
     if (!empty($plurals)) {
         return $plural;
     }
     return $singular;
 }
コード例 #10
0
 /**
  * testStarted method
  *
  * @access public
  * @return void
  */
 function testStarted()
 {
     $this->assertTrue($this->Session->started());
     unset($_SESSION);
     $_SESSION = null;
     $this->assertFalse($this->Session->started());
     $this->assertTrue($this->Session->start());
     $session = new CakeSession(null, false);
     $this->assertTrue($session->started());
     unset($session);
 }
コード例 #11
0
 /**
  * Get the version data from the Model based on settings and deleting
  * this is used in beforeDelete and beforeSave
  *
  * @param Model model
  * @param boolean deleted
  * @return boolean
  */
 private function saveVersion(Model $Model, $delete = false)
 {
     $model_id = 0;
     $Model->oldData = null;
     $Model->versionData = null;
     if ($Model->id) {
         $model_id = $Model->id;
     }
     if (isset($Model->data[$Model->alias][$Model->primaryKey]) && !empty($Model->data[$Model->alias][$Model->primaryKey])) {
         $model_id = $Model->data[$Model->alias][$Model->primaryKey];
     }
     if (empty($model_id)) {
         return false;
     }
     if (isset($Model->data['create_version'])) {
         return false;
     }
     // cache the data in case the model has some afterfind stuff that sets data
     $data = $Model->data;
     // find the oldData / the Current Data before this version is saved
     $Model->oldData = $Model->find('first', array('conditions' => array("{$Model->alias}.{$Model->primaryKey}" => $model_id), 'contain' => $this->settings[$Model->alias]['contain']));
     $Model->versionData = array('user_id' => 0, 'model_id' => $model_id, 'model' => $Model->alias, 'json' => json_encode($Model->oldData), 'is_delete' => $delete, 'url' => IcingUtil::getUrl(), 'ip' => IcingUtil::getIP(), 'is_minor_version' => false);
     if (method_exists($Model, 'getUserId')) {
         $Model->versionData['user_id'] = $Model->getUserId();
     } elseif (class_exists('AuthComponent') && class_exists('CakeSession') && CakeSession::started()) {
         $Model->versionData['user_id'] = AuthComponent::user('id');
     }
     // save the version record
     $output = $this->IcingVersion->saveVersion($Model->versionData, $this->settings[$Model->alias]);
     $Model->versionData['id'] = $this->IcingVersion->id;
     // reset data to the initial value (just in case it got reset somehow)
     $Model->data = $data;
     // return the boolean output (saved version)
     return $output;
 }
コード例 #12
0
ファイル: SessionTest.php プロジェクト: baserproject/basercms
 /**
  * HTTPSによるSession設定テスト
  *
  * @param int $expects 予測値
  * @param string $siteUrl BcEnv.siteUrlの値
  * @param string $sslUrl BcEnv.sslUrlの値
  * @return void
  *
  * @dataProvider sessionConfigureUrlDataProvider
  */
 public function testSessionConfigureUrl($expects, $siteUrl, $sslUrl)
 {
     if (CakeSession::started()) {
         CakeSession::destroy();
     }
     //		p(CakeSession::started());
     ini_set('session.cookie_secure', 0);
     Configure::write('BcEnv.siteUrl', $siteUrl);
     Configure::write('BcEnv.sslUrl', $sslUrl);
     require APP . 'Config' . DS . 'session.php';
     CakeSession::start();
     $this->assertEquals($expects, intval(ini_get('session.cookie_secure')));
 }