public function flash($key = 'flash', $attrs = array()) { $out = false; if (CakeSession::check('Message.' . $key)) { $flash = CakeSession::read('Message.' . $key); $message = $flash['message']; unset($flash['message']); if (!empty($attrs)) { $flash = array_merge($flash, $attrs); } if ($flash['element'] === 'default') { $class = 'success'; if (!empty($flash['params']['class'])) { $class = $flash['params']['class']; } $out = '<div id="' . $key . 'Message" class="alert alert-' . $class . '"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>' . $message . '</div>'; } elseif (!$flash['element']) { $out = $message; } else { $options = array(); if (isset($flash['params']['plugin'])) { $options['plugin'] = $flash['params']['plugin']; } $tmpVars = $flash['params']; $tmpVars['message'] = $message; $out = $this->_View->element($flash['element'], $tmpVars, $options); } CakeSession::delete('Message.' . $key); } return $out; }
protected function _getSite($siteId = null) { $Site = ClassRegistry::init('Sites.Site'); $SiteDomain = $Site->SiteDomain; $SiteMeta = $Site->SiteMeta; $siteDomainTable = $SiteDomain->getDataSource()->fullTableName($SiteDomain, true, true); $siteMetaTable = $Site->SiteMeta->getDataSource()->fullTableName($SiteMeta, true, true); $options = array('recursive' => false, 'fields' => array('Site.id', 'Site.title', 'Site.tagline', 'Site.theme', 'Site.timezone', 'Site.locale', 'Site.status', 'SiteMeta.robots', 'SiteMeta.keywords', 'SiteMeta.description'), 'joins' => array(array('table' => $siteDomainTable, 'alias' => 'SiteDomain', 'conditions' => array('SiteDomain.site_id = Site.id'))), array('table' => $siteMetaTable, 'alias' => 'SiteMeta', 'conditions' => array('SiteMeta.site_id = Site.id'))); $host = env('HTTP_HOST'); if (empty($siteId)) { $options['joins'][0]['conditions']['SiteDomain.domain LIKE'] = '%' . $host; $options['cache'] = array('name' => 'sites_' . $host, 'config' => 'sites'); } else { $options['conditions'] = array('Site.id' => $siteId); $options['cache'] = array('name' => 'sites_' . $siteId, 'config' => 'sites'); } $site = $Site->find('first', $options); if (empty($site)) { $site = $Site->find('first', array('recursive' => false, 'fields' => array('id', 'title', 'tagline', 'theme', 'timezone', 'locale', 'status'), 'joins' => array(array('table' => $siteDomainTable, 'alias' => 'SiteDomain', 'conditions' => array('SiteDomain.site_id = Site.id'))), array('table' => $siteMetaTable, 'alias' => 'SiteMeta', 'conditions' => array('SiteMeta.site_id = Site.id')), 'conditions' => array('Site.default' => 1))); } if ($siteId === null && CakeSession::check(self::$_sessionKey) && ($active = CakeSession::read(self::$_sessionKey))) { $found = $SiteDomain->find('count', array('cache' => array('name' => 'sites_count_' . $host, 'config' => 'sites'), 'conditions' => array('SiteDomain.domain' => $host))); if ($found == 0) { $site = $active; } } return $site; }
/** * Check Auth is user is admin */ public function setup(Model $model, $settings = array()) { parent::setup($model, $settings); if (CakeSession::check('Auth')) { $this->_isAdmin = CakeSession::read('Auth.User.is_admin') ? true : false; } }
/** * Checks to see if there is already a logged in session */ public function __construct() { if (CakeSession::check('auth') && CakeSession::read('auth') == TRUE) { $this->status = TRUE; $this->admin_user = CakeSession::read('admin_user'); } }
public function flash($key = 'flash', $attrs = array()) { $out = false; if (CakeSession::check('Message.' . $key)) { $flash = CakeSession::read('Message.' . $key); if (is_array($flash)) { foreach ($flash as $fkey => $msg) { $message = $msg['message']; // unset($flash[$fkey]['message']); if (!empty($attrs)) { $msg = array_merge($msg, $attrs); } if ($msg['element'] === 'default') { $class = 'message'; if (!empty($msg['params']['class'])) { $class = $msg['params']['class']; } $out .= '<div id="' . $key . 'Message" class="' . $class . '">' . $message . '</div>'; } elseif (!$msg['element']) { $out .= $message; } else { $options = array(); if (isset($msg['params']['plugin'])) { $options['plugin'] = $msg['params']['plugin']; } $tmpVars = $msg['params']; $tmpVars['message'] = $message; $out .= $this->_View->element($msg['element'], $tmpVars, $options); } CakeSession::delete('Message.' . $key . '.' . $fkey); } } else { $message = $flash['message']; unset($flash['message']); if (!empty($attrs)) { $flash = array_merge($flash, $attrs); } if ($flash['element'] === 'default') { $class = 'message'; if (!empty($flash['params']['class'])) { $class = $flash['params']['class']; } $out = '<div id="' . $key . 'Message" class="' . $class . '">' . $message . '</div>'; } elseif (!$flash['element']) { $out = $message; } else { $options = array(); if (isset($flash['params']['plugin'])) { $options['plugin'] = $flash['params']['plugin']; } $tmpVars = $flash['params']; $tmpVars['message'] = $message; $out = $this->_View->element($flash['element'], $tmpVars, $options); } CakeSession::delete('Message.' . $key); } } return $out; }
public function initialize(Controller $controller) { if (CakeSession::check('Config.language')) { Configure::write('Config.language', CakeSession::read('Config.language')); } if (CakeSession::check('Config.language')) { Configure::write('Config.language', CakeSession::read('Config.language')); } }
public function beforeRender() { parent::beforeRender(); $this->set("title_for_layout", "サマリー"); if (CakeSession::check('errMsg')) { $this->set("errMsg", CakeSession::read('errMsg')); CakeSession::delete('errMsg'); } }
public function __construct($id = false, $table = null, $ds = null) { parent::__construct($id, $table, $ds); if (!CakeSession::check($this->_strategy)) { $config = ClassRegistry::init('Opauth.OpauthSetting')->findByName($this->_strategy); if (!empty($config['OpauthSetting'])) { CakeSession::write($this->_strategy, $config['OpauthSetting']); } } $this->_config = CakeSession::read($this->_strategy); }
public function index() { $loginId = $this->_checkLogin(); if (!empty($loginId)) { $this->redirect('../summary/'); } if (CakeSession::check('errMsg')) { $this->set("errMsg", CakeSession::read('errMsg')); CakeSession::delete('errMsg'); } }
public function currentBasketId() { if (!CakeSession::check('WebshopShoppingBasket.current_basket_id')) { $basketId = $this->createBasket(); if (!$basketId) { return false; } CakeSession::write('WebshopShoppingBasket.current_basket_id', $basketId); } return CakeSession::read('WebshopShoppingBasket.current_basket_id'); }
/** * Used to render the message set in FlashComponent::set() * * In your view: $this->Flash->render('somekey'); * Will default to flash if no param is passed * * You can pass additional information into the flash message generation. This allows you * to consolidate all the parameters for a given type of flash message into the view. * * ``` * echo $this->Flash->render('flash', array('params' => array('name' => $user['User']['name']))); * ``` * * This would pass the current user's name into the flash message, so you could create personalized * messages without the controller needing access to that data. * * Lastly you can choose the element that is used for rendering the flash message. Using * custom elements allows you to fully customize how flash messages are generated. * * ``` * echo $this->Flash->render('flash', array('element' => 'my_custom_element')); * ``` * * If you want to use an element from a plugin for rendering your flash message * you can use the dot notation for the plugin's element name: * * ``` * echo $this->Flash->render('flash', array( * 'element' => 'MyPlugin.my_custom_element', * )); * ``` * * @param string $key The [Message.]key you are rendering in the view. * @param array $options Additional options to use for the creation of this flash message. * Supports the 'params', and 'element' keys that are used in the helper. * @return string|null Rendered flash message or null if flash key does not exist * in session. * @throws UnexpectedValueException If value for flash settings key is not an array. */ public function render($key = 'flash', $options = array()) { if (!CakeSession::check("Message.{$key}")) { return; } $flash = CakeSession::read("Message.{$key}"); if (!is_array($flash)) { throw new UnexpectedValueException(sprintf('Value for flash setting key "%s" must be an array.', $key)); } $flash = $options + $flash; CakeSession::delete("Message.{$key}"); return $this->_View->element($flash['element'], $flash); }
public function getSelectedRate() { if (CakeSession::check('DrexCartOrder')) { $order = CakeSession::read('DrexCartOrder'); if (isset($order['shipping_option'])) { foreach ($this->rates as $rate) { if ($rate['code'] == $order['shipping_option']) { return $rate; } } } } return false; }
public function captcha(Model $Model, $check) { $value = array_values($check); $value = $value[0]; $field = key($check); if (CakeSession::check('captcha')) { $builder = new CaptchaBuilder(); $builder->setPhrase(CakeSession::read('captcha')); if ($builder->testPhrase($value)) { return true; } } return false; }
public function processAction(Model $model, $controller) { if (CakeSession::check('Auth.User') == false) { $controller->redirect($controller->Auth->loginAction); } $model->controller = $controller; $controller->autoRender = false; $params = $controller->request->params; $action = 'index'; $plugin = $params['plugin']; if (!empty($params['pass'])) { $action = array_shift($params['pass']); } $model->action = $action; $controller->set('action', $action); $module = $controller->action; $model->beforeAction(); $result = call_user_func_array(array($model, $action), $params['pass']); $model->afterAction(); if (!is_null($plugin)) { //$name = $plugin . '/' . $name; } if ($model->render === 'auto') { if ($action == 'add' || $action == 'edit') { $controller->render('../Elements/templates/edit'); } else { if ($action == 'view') { $controller->render('../Elements/templates/view'); } } } else { if ($model->render === true) { $controller->render($module . '/' . $action); } else { if ($model->render === 'override') { $controller->render($model->render_override); } else { if ($model->render !== false) { $controller->render($module . '/' . $model->render); } } } } return $result; }
public function flash($key = 'flash', $attrs = array()) { $out = false; if (CakeSession::check('Message.' . $key)) { $flash = CakeSession::read('Message.' . $key); $message = $flash['message']; unset($flash['message']); if (!empty($attrs)) { $flash = array_merge($flash, $attrs); } $tmpVars = $flash['params']; $tmpVars['message'] = $message; $tmpOptions = array('plugin' => 'TwitterBootstrap'); $out = $this->_View->element('alert', $tmpVars, $tmpOptions); CakeSession::delete('Message.' . $key); } return $out; }
public function reportGetData() { $currentModel = 'Staff'; $rawFields = $this->getFields(); $conditions = array(); App::uses('CakeSession', 'Model/Datasource'); if (CakeSession::check($currentModel . '.search.conditions')) { $sessionConditions = CakeSession::read($currentModel . '.search.conditions'); $conditions = $this->paginateConditions($sessionConditions); } $order = array(); if (CakeSession::read($currentModel . '.search.sort.processedOrder')) { $order = CakeSession::read($currentModel . '.search.sort.processedOrder'); } $data = $this->find('all', array('recursive' => 0, 'conditions' => $conditions, 'order' => $order)); $data = $this->handleOptionsInData($rawFields, $data); return $data; }
function beforeFind($queryData) { if(CakeSession::check('Auth.User')){ $group = CakeSession::read('Auth.User.group_id');//read the entity id from the session $user = CakeSession::read('Auth.User._id'); if($group!='1'){// only limit data if it's not a admin user. needs to be based on name in future if(isset($this->_schema['user_id'])) { //use a condition to limit data $queryData['conditions'][$this->name.'.user_id'] = $user; return $queryData; } }else{ //Do nothing return $queryData; } }else{ //Do nothing return $queryData; } }
/** * Get the current user from the session. * * @param string $key field to retrive. Leave null to get entire User record * @return mixed User record. or null if no user is logged in. * @link http://book.cakephp.org/view/1264/user */ public static function user($key = null) { if (!empty(static::$loggedInUser)) { return static::$loggedInUser; } if (!CakeSession::check(static::$sessionKey)) { return null; } $user = CakeSession::read(static::$sessionKey); if (is_string($user)) { $class = static::$documentModel; $user = static::$loggedInUser = $class::find($user); } if ($key == null) { return $user; } if (isset($user[$key])) { return $user[$key]; } return null; }
public function save($data) { if (isset($data['id'])) { if (CakeSession::write('TempItems.' . $data['id'], $data)) { return true; } else { return false; } } if (CakeSession::check('TempItems')) { $ret = CakeSession::read('TempItems'); array_push($ret, $data); } else { $ret = array($data); } if (CakeSession::write('TempItems', $ret)) { return true; } else { return false; } }
/** * Find, setup, and get the AB test, if we're using Sessions setup in the config, look at that first. * @param array of options * - debug (if true, will always return the test even if it's not active, and regardless of roll) * - return (test|roll|both) default test. * - refresh (will preform the search as normal without the cached test result) default false * @return mixed array test if found and rolled, or boolean depending on return option. */ public function getTest($options = array()) { $options = array_merge(array('debug' => false, 'return' => 'test', 'refresh' => false), (array) $options); $retval = array('test' => false, 'roll' => false); if (!$options['refresh'] && $this->test) { return $this->test; } $this->loadModel('SeoABTest'); if ($test = $this->SeoABTest->findTestByUri(null, $options['debug'])) { if ($this->SeoABTest->isTestable($test)) { $retval['test'] = $test; if (SeoUtil::getConfig('abTesting.session')) { $ab_tests = CakeSession::check('Seo.ABTests') ? CakeSession::read('Seo.ABTests') : array(); } else { $ab_tests = array(); } if (is_array($ab_tests) && isset($ab_tests[$test['SeoABTest']['id']])) { $retval['roll'] = !!$ab_tests[$test['SeoABTest']['id']]; } elseif ($options['debug'] || $this->SeoABTest->roll($test)) { $ab_tests[$test['SeoABTest']['id']] = $test; $retval['roll'] = true; } else { $ab_tests[$test['SeoABTest']['id']] = false; $retval['roll'] = false; } if (SeoUtil::getConfig('abTesting.session')) { CakeSession::write('Seo.ABTests', $ab_tests); } $this->test = $retval; } } switch ($options['return']) { case 'test': return $retval['test']; case 'roll': return $retval['roll']; default: return $retval; } }
public function authenticate(MOXMAN_Auth_User $user) { $config = MOXMAN::getConfig(); // Check logged in key $sessionValue = CakeSession::read($config->get("CakeAuthenticator.logged_in_key", "loggedin")); if (!$sessionValue || $sessionValue === "false") { return false; } // Extend config with session prefixed sessions $configPrefix = $config->get("CakeAuthenticator.config_prefix", "moxiemanager"); if ($configPrefix && CakeSession::check($configPrefix)) { $configItems = CakeSession::read($configPrefix); $config->extend($this->flattenArray($configItems)); } // Replace ${user} with all config items $key = $config->get("CakeAuthenticator.user_key"); if ($key && CakeSession::check($key)) { $config->replaceVariable("user", CakeSession::read($key)); } // The user is authenticated so let them though return true; }
/** * Used to check if a session variable is set * * In your controller: $this->Session->check('Controller.sessKey'); * * @param string $name the name of the session key you want to check * @return boolean true is session variable is set, false if not * @access public */ function check($name) { if ($this->__active === true) { $this->__start(); return parent::check($name); } return false; }
/** * Get the current user. * * Will prefer the static user cache over sessions. The static user * cache is primarily used for stateless authentication. For stateful authentication, * cookies + sessions will be used. * * @param string $key field to retrieve. Leave null to get entire User record * @return array|null User record. or null if no user is logged in. * @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#accessing-the-logged-in-user */ public static function user($key = null) { if (!empty(self::$_user)) { $user = self::$_user; } elseif (self::$sessionKey && CakeSession::check(self::$sessionKey)) { $user = CakeSession::read(self::$sessionKey); } else { return null; } if ($key === null) { return $user; } return Hash::get($user, $key); }
public function applyPromoCode($CanteenOrder) { //set all the promo codes on the order $currency = ClassRegistry::init("Currency"); $user_id = false; if (CakeSession::check("Auth.User.id")) { $user_id = CakeSession::read("Auth.User.id"); } #User Account Promo Code if (isset($CanteenOrder['CanteenOrder']['user_account_canteen_promo_code_id']) && !empty($CanteenOrder['CanteenOrder']['user_account_canteen_promo_code_id'])) { $uap = $this->find("first", array("conditions" => array("CanteenPromoCode.id" => $CanteenOrder['CanteenOrder']['user_account_canteen_promo_code_id']), "contain" => array())); if (isset($uap['CanteenPromoCode']['id'])) { $CanteenOrder['UserAccountCanteenPromoCode'] = $uap['CanteenPromoCode']; } } #Shipping Promo Code ### For Certain Users $free_shipping_users = array('4d715e72-7124-486a-9129-7ace0ab55011', '4d54b193-7c1c-4741-bdfe-0fe90a000269'); if (in_array($user_id, $free_shipping_users)) { $CanteenOrder['CanteenOrder']['shipping_total'] = 0.0; $CanteenOrder['CanteenOrder']['shipping_canteen_promo_code_id'] = 2; //get the promo code $code = $this->find("first", array("contain" => array(), "conditions" => array("CanteenPromoCode.id" => 2))); $CanteenOrder['ShippingCanteenPromoCode'] = $code['CanteenPromoCode']; } /* if( env('GEOIP_COUNTRY_CODE') == "US" && $CanteenOrder['CanteenOrder']['sub_total'] >= 74.95 ) { $CanteenOrder['CanteenOrder']['shipping_total'] = 0.00; $CanteenOrder['CanteenOrder']['shipping_canteen_promo_code_id'] = 2; //get the promo code $code = $this->find("first",array( "contain"=>array(), "conditions"=>array( "CanteenPromoCode.id"=>2 ) )); $CanteenOrder['ShippingCanteenPromoCode'] = $code['CanteenPromoCode']; } */ #Promotion Promo Code //check to see if there are more than three items if (count($CanteenOrder['CanteenOrderItem']) >= 3) { $CanteenOrder['UserAccountCanteenPromoCode'] = null; $uap = $this->find("first", array("conditions" => array("CanteenPromoCode.id" => 3), "contain" => array())); if (isset($uap['CanteenPromoCode']['id'])) { $CanteenOrder['PromotionCanteenPromoCode'] = $uap['CanteenPromoCode']; } } #Standard Promo Code #Calculate all the discounts $discount = 0; if (isset($CanteenOrder['UserAccountCanteenPromoCode']['rate'])) { $discount += $CanteenOrder['UserAccountCanteenPromoCode']['rate'] / 100 * $CanteenOrder['CanteenOrder']['sub_total']; } if (isset($CanteenOrder['PromotionCanteenPromoCode']['rate'])) { $discount += $CanteenOrder['PromotionCanteenPromoCode']['rate'] / 100 * $CanteenOrder['CanteenOrder']['sub_total']; } if ($discount > 0) { $discount = "-" . $discount; } $CanteenOrder['CanteenOrder']['discount_total'] = $discount; $CanteenOrder['CanteenOrder']['sub_total'] += $discount; $CanteenOrder['CanteenOrder']['taxable_total'] += $discount; return $CanteenOrder; }
/** * Used to check if a session variable is set * * In your controller: $this->Session->check('Controller.sessKey'); * * @param string $name the name of the session key you want to check * @return boolean true is session variable is set, false if not * @link http://book.cakephp.org/2.0/en/core-libraries/components/sessions.html#SessionComponent::check */ public function check($name) { return CakeSession::check($name); }
/** * Used to render the message set in Controller::Session::setFlash() * * In your view: $session->flash('somekey'); * Will default to flash if no param is passed * * @param string $key The [Message.]key you are rendering in the view. * @return string Will echo the value if $key is set, or false if not set. * @access public */ function flash($key = 'flash') { if ($this->__active === true && $this->__start()) { if (parent::check('Message.' . $key)) { $flash = parent::read('Message.' . $key); if ($flash['layout'] == 'default') { if (!empty($flash['params']['class'])) { $class = $flash['params']['class']; } else { $class = 'message'; } $out = '<div id="' . $key . 'Message" class="' . $class . '">' . $flash['message'] . '</div>'; } elseif ($flash['layout'] == '' || $flash['layout'] == null) { $out = $flash['message']; } else { $view =& ClassRegistry::getObject('view'); list($tmpVars, $tmpTitle) = array($view->viewVars, $view->pageTitle); list($view->viewVars, $view->pageTitle) = array($flash['params'], ''); $out = $view->renderLayout($flash['message'], $flash['layout']); list($view->viewVars, $view->pageTitle) = array($tmpVars, $tmpTitle); } echo $out; parent::del('Message.' . $key); return true; } } return false; }
/** * Used to render the message set in Controller::Session::setFlash() * * In your view: $this->Session->flash('somekey'); * Will default to flash if no param is passed * * You can pass additional information into the flash message generation. This allows you * to consolidate all the parameters for a given type of flash message into the view. * * {{{ * echo $this->Session->flash('flash', array('params' => array('class' => 'new-flash'))); * }}} * * The above would generate a flash message with a custom class name. Using $attrs['params'] you * can pass additional data into the element rendering that will be made available as local variables * when the element is rendered: * * {{{ * echo $this->Session->flash('flash', array('params' => array('name' => $user['User']['name']))); * }}} * * This would pass the current user's name into the flash message, so you could create peronsonalized * messages without the controller needing access to that data. * * Lastly you can choose the element that is rendered when creating the flash message. Using * custom elements allows you to fully customize how flash messages are generated. * * {{{ * echo $this->Session->flash('flash', array('element' => 'my_custom_element')); * }}} * * @param string $key The [Message.]key you are rendering in the view. * @return array $attrs Additional attributes to use for the creation of this flash message. * Supports the 'params', and 'element' keys that are used in the helper. * @access public * @link http://book.cakephp.org/view/1466/Methods * @link http://book.cakephp.org/view/1467/flash */ public function flash($key = 'flash', $attrs = array()) { $out = false; if (CakeSession::check('Message.' . $key)) { $flash = CakeSession::read('Message.' . $key); $message = $flash['message']; unset($flash['message']); if (!empty($attrs)) { $flash = array_merge($flash, $attrs); } if ($flash['element'] == 'default') { $class = 'message'; if (!empty($flash['params']['class'])) { $class = $flash['params']['class']; } $out = '<div id="' . $key . 'Message" class="' . $class . '">' . $message . '</div>'; } elseif ($flash['element'] == '' || $flash['element'] == null) { $out = $message; } else { $tmpVars = $flash['params']; $tmpVars['message'] = $message; $out = $this->_View->element($flash['element'], $tmpVars); } CakeSession::delete('Message.' . $key); } return $out; }
/** * Used to render the message set in Controller::Session::setFlash() * * In your view: $session->flash('somekey'); * Will default to flash if no param is passed * * @param string $key The [Message.]key you are rendering in the view. * @return boolean|string Will return the value if $key is set, or false if not set. * @access public * @link http://book.cakephp.org/view/1466/Methods * @link http://book.cakephp.org/view/1467/flash */ function flash($key = 'flash') { $out = false; if ($this->__active === true && $this->__start()) { if (parent::check('Message.' . $key)) { $flash = parent::read('Message.' . $key); if ($flash['element'] == 'default') { if (!empty($flash['params']['class'])) { $class = $flash['params']['class']; } else { $class = 'message'; } $out = '<div id="' . $key . 'Message" class="' . $class . '">' . $flash['message'] . '</div>'; } elseif ($flash['element'] == '' || $flash['element'] == null) { $out = $flash['message']; } else { $view =& ClassRegistry::getObject('view'); $tmpVars = $flash['params']; $tmpVars['message'] = $flash['message']; $out = $view->element($flash['element'], $tmpVars); } parent::delete('Message.' . $key); } } return $out; }
public function getSearchHistory($searchType) { return CakeSession::check($searchType) ? CakeSession::read($searchType) : []; }
/** * Get the current user. * * Will prefer the static user cache over sessions. The static user * cache is primarily used for stateless authentication. For stateful authentication, * cookies + sessions will be used. * * @param string $key field to retrieve. Leave null to get entire User record * @return mixed User record. or null if no user is logged in. * @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#accessing-the-logged-in-user */ public static function user($key = null) { if (empty(self::$_user) && !CakeSession::check(self::$sessionKey)) { return null; } if (!empty(self::$_user)) { $user = self::$_user; } else { $user = CakeSession::read(self::$sessionKey); } if ($key === null) { return $user; } if (isset($user[$key])) { return $user[$key]; } return null; }