public function searchAction()
 {
     if ($this->getRequest()->isXmlHttpRequest()) {
         $request = $this->getRequest();
         $sm = $this->getServiceLocator();
         $oFormModel = $sm->get('FormsElementTable');
         $aFormModel = $oFormModel->getPolaFormularza(2);
         if ($request->isPost()) {
             $oPost = $request->getPost();
             $aPost = $oPost->toArray();
             $container = new \Zend\Session\Container($this->sSessionNameSpace);
             foreach ($aPost as $klucz => $wartosc) {
                 $container->offsetSet($klucz, $wartosc);
             }
             $ind = $this->params()->fromQuery('orderby', 0);
             $direction = $this->params()->fromQuery('direction', 'desc');
             $container->offsetSet('direction', $direction);
             $container->offsetSet('orderby', $ind);
             $xml = '<info>Ok</info>';
             $this->getResponse()->getHeaders()->addHeaders(array('Content-type' => 'text/xml'));
             return $this->getResponse()->setContent($xml);
         }
         $oForm = new Form();
         $oForm->setPokazPrzyciskZapisz(false);
         $xml = $oForm->getXMLForm($aFormModel);
         $this->getResponse()->getHeaders()->addHeaders(array('Content-type' => 'text/xml'));
         return $this->getResponse()->setContent($xml);
     }
 }
示例#2
0
 public function captcha2()
 {
     $path = BASEPATH . '../resources/captcha/' . (date('Y') . '/' . date('m') . '/' . date('d'));
     if (!file_exists($path)) {
         mkdir($path, 0777, TRUE);
     }
     $session = new Zend\Session\Container('ZEND_PARANGARI');
     $session->offsetSet('text1', 'value1');
     //$session->set
     $obj = new Zend\Captcha\Image();
     $obj->setImgDir($path);
     $obj->setFont(BASEPATH . '../application/third_party/fonts/LesJoursHeureux.otf');
     $obj->setFontSize(40);
     $obj->setWidth(250);
     $obj->setHeight(100);
     $obj->setDotNoiseLevel(40);
     $obj->setLineNoiseLevel(3);
     $obj->setWordlen(6);
     $obj->setSession($session);
     $string_captcha_ID = $obj->generate();
     echo $string_captcha_ID . "<br/>";
     echo $obj->getWord();
     $obj->isValid($string_captcha_ID);
     Helper_Log::write($_SESSION);
 }
 public function onDispatch(\Zend\Mvc\MvcEvent $e)
 {
     $id = (int) $this->getEvent()->getRouteMatch()->getParam('id_container');
     $container = new \Zend\Session\Container($this->sSessionNameSpace);
     $container->offsetSet('id_container', $id);
     $this->aAdditionalArray = array('id_container' => $id);
     return parent::onDispatch($e);
 }
示例#4
0
 public function authenticate(AuthEvent $e)
 {
     // check if cookie needs to be set, only when prior auth has been successful
     if ($e->getIdentity() !== null && $e->getRequest()->isPost() && $e->getRequest()->getPost()->get('remember_me') == 1) {
         $userObject = $this->getUserMapper()->findById($e->getIdentity());
         $this->getRememberMeService()->createSerie($userObject->getId());
         /**
          *  If the user has first logged in with a cookie,
          *  but afterwords login with identity/credential
          *  we remove the "cookieLogin" session.
          */
         $session = new \Zend\Session\Container('zfcuser');
         $session->offsetSet("cookieLogin", false);
         return;
     }
     if ($this->isSatisfied()) {
         $storage = $this->getStorage()->read();
         $e->setIdentity($storage['identity'])->setCode(AuthenticationResult::SUCCESS)->setMessages(array('Authentication successful.'));
         return;
     }
     $cookies = $e->getRequest()->getCookie();
     // no cookie present, skip authentication
     if (!isset($cookies['remember_me'])) {
         return false;
     }
     $cookie = explode("\n", $cookies['remember_me']);
     $rememberMe = $this->getRememberMeMapper()->findByIdSerie($cookie[0], $cookie[1]);
     if (!$rememberMe) {
         $this->getRememberMeService()->removeCookie();
         return false;
     }
     if ($rememberMe->getToken() !== $cookie[2]) {
         // H4x0r
         // @TODO: Inform user of theft, change password?
         $this->getRememberMeMapper()->removeAll($cookie[0]);
         $this->getRememberMeService()->removeCookie();
         $this->setSatisfied(false);
         $e->setCode(AuthenticationResult::FAILURE)->setMessages(array('Possible identity theft detected.'));
         return false;
     }
     $userObject = $this->getUserMapper()->findById($cookie[0]);
     $this->getRememberMeService()->updateSerie($rememberMe);
     // Success!
     $e->setIdentity($userObject->getId());
     $this->setSatisfied(true);
     $storage = $this->getStorage()->read();
     $storage['identity'] = $e->getIdentity();
     $this->getStorage()->write($storage);
     $e->setCode(AuthenticationResult::SUCCESS)->setMessages(array('Authentication successful.'));
     // Reference for weak login. Should not be allowed to change PW etc.
     $session = new \Zend\Session\Container('zfcuser');
     $session->offsetSet("cookieLogin", true);
 }
示例#5
0
<?php

require_once './autoloader.php';
require_once EVA_LIB_PATH . '/Markdown/markdownextra.php';
$sm1 = new Zend\Session\SessionManager();
$sm1->setId(md5('session1'));
$sessionContainer1 = new Zend\Session\Container('Namespace', $sm1);
$sessionContainer1->offsetSet('testKey', 'foo');
echo $sessionContainer1->offsetGet('testKey');
//output foo
$sm2 = new Zend\Session\SessionManager();
$sm2->setId(md5('session2'));
/*
$sessionContainer2 = new Zend\Session\Container('Namespace', $sm2);
$sessionContainer2->offsetSet('testKey', 'bar');

echo $sessionContainer2->offsetGet('testKey'); //output bar
*/
示例#6
0
 public function addComment($data)
 {
     $comment = new CommentEntity();
     $form = $this->getCommentForm();
     $form->setHydrator(new ClassMethods());
     $form->bind($comment);
     $form->setData($data);
     if (!$form->isValid()) {
         $container = new \Zend\Session\Container();
         $container->offsetSet('form_errors', $form->getMessages());
         return false;
     }
     $comment = $form->getData();
     $comment->setComment($data['comment']);
     $comment->setProjectId('1');
     //$comment->setDtc('date');
     $this->repository->saveEntity($comment);
     return $comment;
 }
示例#7
0
 public function _init(Dispatcher $dispatcher)
 {
     // 引入Composer,Yaf扩展的配置项yaf.use_spl_autoload务必设置为1
     if (file_exists(ROOT_PATH . '/vendor/autoload.php')) {
         $loader = (include ROOT_PATH . '/vendor/autoload.php');
         //$loader->add("",ROOT_PATH.'/library');
         //$loader->addPsr4("Zend\\",ROOT_PATH.'/library/Zend');
         Registry::set('loader', $loader);
     }
     // 禁止自动渲染
     $dispatcher->autoRender(FALSE);
     // 保存配置
     $this->_config = Application::app()->getConfig();
     Registry::set('config', $this->_config);
     // 报错设置
     if ($this->_config->global->showError) {
         error_reporting(-1);
         ini_set('display_errors', 'On');
     }
     // 加解密
     if (!empty($this->_config->global->key)) {
         Registry::set('enc', function () {
             $blockCipher = BlockCipher::factory('mcrypt', array('algo' => 'aes'));
             $blockCipher->setKey($this->_config->global->key);
             return $blockCipher;
         });
     }
     // 命令行方式,跳过SESSION
     if (!defined("RUN_IN_CLI")) {
         // 保存路径
         $sessionConfig = $this->_config->session->toArray();
         if (isset($sessionConfig['save_path'])) {
             @mkdir($sessionConfig['save_path'], 0777, true);
         }
         // 配置
         $config = new SessionConfig();
         $config->setOptions($sessionConfig);
         // 会话管理器
         $manager = new SessionManager($config);
         // 开启会话
         $manager->start();
         // 验证会话
         $manager->getValidatorChain()->attach('session.validate', array(new HttpUserAgent(), 'isValid'));
         if (!$manager->isValid()) {
             $manager->destroy();
             throw new \Exception("会话验证失败");
         }
         // 会话Token
         $default = new Zend\Session\Container();
         if (empty($default->offsetGet('securityToken'))) {
             $default->offsetSet('securityToken', md5(uniqid(rand(), true)));
         }
         // 保存实例
         Registry::set('session', $default);
         Registry::set('sm', $manager);
     }
     // 数据库
     Registry::set('db', function () {
         $mysqlMasterConfig = $this->_config->mysql->master->toArray();
         $adapter = new Adapter($mysqlMasterConfig);
         $connect = $adapter->getDriver()->getConnection();
         for ($i = 0; $i < 5; $i++) {
             if ($connect->isConnected()) {
                 break;
             }
             $connect->connect();
         }
         return $adapter;
     });
     // 邮件
     Registry::set('mail', function () {
         $options = new SmtpOptions($this->_config->smtp->toArray());
         $mail = new SmtpTransport();
         $mail->setOptions($options);
         return $mail;
     });
     // 日志
     Registry::set('logger', function () {
         $logger = new Zend\Log\Logger();
         $writer = new Zend\Log\Writer\Stream($this->_config->log->path . '/' . date("Ymd") . ".log");
         $logger->addWriter($writer);
         return $logger;
     });
 }