public function loginAction() { $user_id = $this->request->get('userId'); $user_info = User::getUserInfoById($user_id); if (!empty($user_info)) { $user = new SessionBag('user'); foreach ($user_info as $key => $value) { $user->set($key, $value); } $client_type = $this->request->get('clientType'); $ver = $this->request->get('ver'); $uuid = $this->request->get('uuid'); $user->set('client_type', $client_type); $user->set('ver', $ver); $user->set('uuid', $uuid); } else { //没有user_id参数并且没有session则登录为游客 $user = new SessionBag('user'); //user_id设置为客户端IP $user->set('id', 0); $user->set('user_id', 'WEIBO_ACCOUNT'); $user->set('nickname', '游客'); } $session_id = $this->session->getId(); $this->view->setVars(array('session_id' => $session_id, 'user_info' => $user->getIterator())); }
/** * Tests read and write * * @author Kamil Skowron <*****@*****.**> * @since 2015-07-17 */ public function testBagGetAndSet() { $this->specify("Session bag incorrectly handling writing and reading", function () { @session_start(); // Using getters and setters $bag = new Bag('test1'); $bag->set('a', ['b' => 'c']); expect($bag->get('a'))->equals(['b' => 'c']); expect($_SESSION['test1']['a'])->same(['b' => 'c']); // Using direct access $bag = new Bag('test2'); $bag->{'a'} = ['b' => 'c']; expect($bag->{'a'})->equals(['b' => 'c']); expect($_SESSION['test2']['a'])->same(['b' => 'c']); @session_destroy(); }); }
/** * @param \Phalcon\DiInterface $di */ public function __construct(\Phalcon\DiInterface $di = null) { parent::__construct('viewer'); $this->setDi($di); }
/** * {@inheritdoc} */ public function has($property) { return $this->storage->has($property); }
/** * Get all value filter * * @return array Array value filter when coder use function addFilter */ public function getFilter() { $sessionBagKey = $this->_module . '_' . $this->_controller . '_' . $this->_action . '_filter'; $filterSessionGlobal = new SessionBag('ZCMS_GB_FILTER'); $filterSession = []; if ($filterSessionGlobal->has($sessionBagKey)) { $filterSession = $filterSessionGlobal->get($sessionBagKey); } if (count($this->_filterOptions)) { foreach ($this->_filterOptions as $key => $item) { if ($item['method'] == 'POST') { $this->_filter[$key] = $this->request->getPost($key, $item['type']); if ($this->_filter[$key] == null && $this->_filter[$key] !== $item['value']) { if (array_key_exists($key, $filterSession) && $filterSession[$key] != null) { $this->_filter[$key] = $filterSession[$key]; } else { $this->_filter[$key] = $item['value']; } } } else { $this->_filter[$key] = $this->request->getQuery($key, $item['type']); if ($this->_filter[$key] == null && $this->_filter[$key] !== $item['value']) { if (array_key_exists($key, $filterSession) && $filterSession[$key] != null) { $this->_filter[$key] = $filterSession[$key]; } else { $this->_filter[$key] = $item['value']; } } } } } $filterSessionGlobal->set($sessionBagKey, $this->_filter); return $this->_filter; }