public function __construct()
 {
     $this->app = App::getInstance();
     $this->view = View::getInstance();
     $this->config = $this->app->getConfig();
     $this->input = InputData::getInstance();
 }
Exemplo n.º 2
0
 /**
  * getLinkByPostId
  *
  * Return redirection link value
  *
  * @param  int    $postID Identification number of post
  * @return string         Redirection link
  */
 public static function getLinkByPostId($postID)
 {
     $conn = \DBI::getConnection('slave');
     // try get post data
     $postData = $conn->sendQuery('SELECT
                 fp.id post_id,
                 ft.id topic_id
             FROM forum_posts fp
             INNER JOIN forum_topics ft
                 ON ft.id = fp.topic_id
             WHERE fp.id = :post_id', array(':post_id' => $postID))->fetch(\PDO::FETCH_OBJ);
     if (!$postData) {
         throw new \SystemErrorException(array('title' => \View::$language->forum_to_post_error, 'description' => \View::$language->forum_to_post_post_not_found));
     }
     // try get post offset
     $postsOffset = $conn->sendQuery('SELECT
                 COUNT(1) cnt
             FROM forum_posts
             WHERE topic_id = :topic_id
                 AND id <= :post_id', array('topic_id' => $postData->topic_id, 'post_id' => $postData->post_id))->fetch(\PDO::FETCH_COLUMN);
     // calculate page number
     $pageNumber = $postsOffset / \App::getConfig('forum')->posts_per_page;
     // TODO posts per page from member custom settings
     $pageNumber = ceil($pageNumber);
     // build link
     $link = '/forum/topic?id=' . $postData->topic_id;
     if ($pageNumber > 1) {
         $link .= '&page=' . $pageNumber;
     }
     $link .= '#topic-post-' . $postData->post_id;
     return $link;
 }
Exemplo n.º 3
0
 /**
  * writeItem
  *
  * Write into log file one report line
  *
  * @param  array $item Loggable report data
  * @return null
  */
 public static function writeItem(array $item)
 {
     $existsLog = false;
     $logDir = APPLICATION . 'logs';
     $logFile = $logDir . '/main.log';
     if (!is_dir($logDir)) {
         exit('Log path ' . $logDir . ' is not directory or not exists!');
     } else {
         if (!is_writable($logDir)) {
             exit('Log path ' . $logDir . ' don\'t have writable permissions!');
         }
     }
     if (is_file($logFile)) {
         if (!is_writable($logFile)) {
             exit('Log file ' . $logFile . ' don\'t have writable permission!');
         }
         $existsLog = true;
         $maxLogSize = App::getConfig('main')->system->log_file_max_size;
         if (filesize($logFile) > $maxLogSize) {
             $logName = date('Y-m-d_H.i.s');
             $archLog = $logDir . '/main_' . $logName . '.log';
             rename($logFile, $archLog);
             $existsLog = false;
         }
     }
     $item['url'] = Request::getRawUrl();
     $item = ($existsLog ? ",\n" : '') . json_encode($item);
     file_put_contents($logFile, $item, LOCK_EX | FILE_APPEND);
     if (!$existsLog) {
         chmod($logFile, 0666);
     }
 }
Exemplo n.º 4
0
 /**
  * Default action
  * @param $args array
  */
 public function index(array $args = array())
 {
     \App::setVariable('pageTitle', 'Hello, World.');
     \App::setVariable('helloWorld', 'This does work.<br>');
     \App::setConfig('hello', 'Hello World');
     echo \App::getConfig('hello');
 }
Exemplo n.º 5
0
 /**
  * processAction
  *
  * Member registration process
  *
  * @return null
  */
 public function processAction()
 {
     // set json context
     \View::setOutputContext('json');
     \View::lockOutputContext();
     // validate form
     $registerForm = new forms\RegisterForm();
     $registerForm->validate();
     if (!$registerForm->isValid()) {
         throw new \MemberErrorException(array('title' => \View::$language->register_error, 'description' => \View::$language->register_proc_err_descr, 'form_messages' => $registerForm->getMessages()));
     }
     $userData = $registerForm->getData();
     // set new user defaults
     $hCnf = \App::getConfig('hosts');
     $mCnf = \App::getConfig('member-defaults');
     $pass = \common\CryptHelper::generateHash($userData->password);
     $userData->group_id = $mCnf->group_id;
     $userData->cookie = \common\HashHelper::getUniqueKey();
     $userData->password = $pass;
     $userData->time_zone = $mCnf->time_zone;
     $userData->status = $mCnf->status;
     $userData->activation_hash = \common\HashHelper::getUniqueKey();
     $userData->avatar = '//' . $hCnf->st . $mCnf->avatar;
     // create a new user
     $UserModel = \App::getInstance('common\\UserModel');
     $UserModel->createUser($userData);
     // TODO send email notification of account activation
     \App::dump($userData);
     // redirect to complete page
     \Storage::write('__register_complete', true);
     throw new \MemberSuccessException(array('redirection' => '/user/register/complete'));
 }
Exemplo n.º 6
0
 public function run()
 {
     $data = $this->_context->get("data", '');
     // Log::Write('【加密数据】Remote Accept:' . $data, Log::DEBUG);
     if ($this->_context->isPOST()) {
         $de_data = Crypt::decrypt($data, App::getConfig('YUC_SECURE_KEY'));
         //  Log::Write('解析的加密数据:' . $de_data, Log::DEBUG);
         $post = json_decode($de_data, TRUE);
         if ($post != '' && is_array($post) && $post['site_key'] == md5(App::getConfig('YUC_SITE_KEY'))) {
             $mod = $post['mod'];
             $act = $post['act'];
             $class = 'Remote_' . $mod;
             if ($act == 'show' && $mod == 'Logs') {
                 $name = $post['name'];
                 $obj = new $class();
                 //self::$_string[' $name']=$name;
                 $ret = $obj->{$act}($name);
             } else {
                 $obj = new $class();
                 $ret = $obj->{$act}();
             }
             Log::Write('Remote Run:' . $mod . ',' . $act . ',' . $ret, Log::DEBUG);
             _returnCryptAjax($ret);
         } else {
             Log::Write('安全认证错误!', Log::DEBUG);
             _returnCryptAjax(array('result' => 0, 'content' => '安全认证比对错误错误!'));
         }
     } else {
         Log::Write('远程控制错误!数据并非POST交互!', Log::DEBUG);
         _returnCryptAjax(array('result' => 0, 'content' => '远程控制错误!数据并非POST交互!'));
     }
 }
Exemplo n.º 7
0
 /**
  * 解析请求
  *
  * @param string $url 链接地址
  * @return Request
  */
 public static function parse($url = null)
 {
     $request = Request::getInstance();
     if (is_null($url)) {
         $path = $request->getPath();
     } else {
         $request->setUrl($url);
         $path = $request->getPath();
     }
     $path = trim($path, '/');
     $mode = App::getConfig()->getURLMode();
     switch ($mode) {
         case 1:
             $Url = self::parseQuery($path);
             break;
         case 2:
             $Url = self::parsePathInfo($path);
             break;
         case 3:
             $Url = self::parseRewrite($path);
             break;
         default:
             $Url = self::parseQuery($path);
     }
     return $Url;
 }
Exemplo n.º 8
0
/**
 * Get / set the specified configuration value.
 *
 * If an array is passed as the key, we will assume you want to set an array of values.
 *
 * @param  array|string  $key
 * @param  mixed  $default
 * @return mixed
 */
function config($key, $default = null)
{
    if (is_array($key)) {
        return App::setConfig($key, $default);
    }
    return App::getConfig($key, $default);
}
Exemplo n.º 9
0
 public static function execute()
 {
     Header('X-Accel-Buffering: no');
     // nginx-1.5.6 及其以上版本支持
     $config = App::getConfig();
     self::checkRateLimit($config['site']['rateLimit']);
     $commands = $config['site']['commands'];
     $param = $_GET + $_POST;
     $host = isset($param['host']) ? $param['host'] : '';
     $cmd = isset($param['cmd']) ? $param['cmd'] : '';
     if (stripos($host, 'localhost') !== FALSE) {
         echo "<script>parent.alert('请输入正确的IP地址或域名');</script>";
         echo '<script>parent.req_complete()</script>';
         exit;
     }
     $ip = gethostbyname($host);
     if (filter_var($ip, FILTER_VALIDATE_IP) === FALSE || $ip == '127.0.0.1') {
         echo "<script>parent.alert('请输入正确的IP地址或域名');</script>";
         echo '<script>parent.req_complete()</script>';
         exit;
     }
     if (isset($commands[$cmd])) {
         call_user_func(array(__CLASS__, $cmd), $ip, $commands[$cmd]);
         echo '<script>parent.req_complete()</script>';
     } else {
         echo "<script>parent.alert('无效命令');</script>";
         echo '<script>parent.req_complete()</script>';
         exit;
     }
 }
Exemplo n.º 10
0
 /**
  * validate
  *
  * Run validation process
  *
  * @return null
  */
 public function validate()
 {
     parent::validate();
     $availableFilters = \App::getConfig('forum')->tracker_filters;
     if (!in_array($this->_data->by, $availableFilters, true)) {
         $this->_isValid = false;
     }
 }
Exemplo n.º 11
0
 /**
  * init
  *
  * Initialization of session storage
  *
  * php.ini used to have session.gc_probability=0 with the comment:
  *
  * "This is disabled in the Debian packages,
  * due to the strict permissions on /var/lib/php5".
  * The strict permissions remain, but session.gc_probability is now enabled.
  *
  * By default there's a 0.1% chance that a call to session_start()
  * will trigger this, but setting session.gc_divisor=1
  * makes this easily reproducible.
  *
  * http://somethingemporium.com/2007/06/obscure-error-with-php5-on-debian-ubuntu-session-phpini-garbage
  *
  * And this use: @ session_start();
  *
  * @return null
  */
 public static function init()
 {
     if (!App::isCLI()) {
         session_name(App::getConfig('main')->system->session_name);
         @session_start();
         self::_setSessionPointer($_SESSION);
     }
 }
Exemplo n.º 12
0
 public function __construct($path)
 {
     if (($config = App::getConfig()->get("path.{$path}", false)) === false) {
         throw new \Exception("No defined path found on config for the route '{$path}'");
     }
     $this->path = $path;
     $this->page = new Page($path, $config);
 }
Exemplo n.º 13
0
 public function __construct(App $app)
 {
     $this->app = $app;
     $dbConfig = $app->getConfig()['db'];
     $provider = strtolower($dbConfig['provider']);
     $provider[0] = strtoupper($provider[0]);
     $connectionClass = __NAMESPACE__ . '\\' . $provider . 'Connection';
     $this->conn = new $connectionClass($dbConfig['host'], $dbConfig['user'], $dbConfig['password'], $dbConfig['name']);
 }
Exemplo n.º 14
0
 /**
  * getLinks
  *
  * Return array of available filter links
  *
  * @param  string $currentFilter Current active filter name
  * @return array                 Array of available filter links
  */
 public static function getLinks($currentFilter)
 {
     $links = array();
     foreach (\App::getConfig('forum')->tracker_filters as $k => $name) {
         $title = \View::$language->{'forum_tracker_by_' . $name . '_title'};
         $url = '/forum/tracker' . ($k ? '?by=' . $name : '');
         $links[] = (object) array('current' => $currentFilter == $name, 'url' => $url, 'title' => $title);
     }
     return $links;
 }
Exemplo n.º 15
0
 /**
  * getConnection
  *
  * Return connection object (instance of self)
  *
  * @param  string $key Key of connection instance
  * @return DBC             Database connection object
  */
 public static function getConnection($key = null)
 {
     if (!$key || sizeof(self::$_connections) == 1) {
         reset(self::$_connections);
         $key = key(self::$_connections);
     }
     if (!array_key_exists($key, self::$_connections)) {
         self::$_connections[$key] = new DBC(App::getConfig('main')->db);
     }
     return self::$_connections[$key];
 }
Exemplo n.º 16
0
 /**
  * getPostsByTopicId
  *
  * Will return array of posts by identification number of topic
  *
  * @param  int   $topicID Identification number of topic
  * @param  int   $offset  Offset number of first post
  * @param  int   $limit   Number of posts per page
  * @return array          Posts data
  */
 public static function getPostsByTopicId($topicID, $offset, $limit)
 {
     $topicPosts = \DBI::getConnection('slave')->sendQuery("SELECT\n\n                    fp.id,\n                    fp.topic_start,\n                    fp.edited_by,\n                    fp.moderated_by,\n                    fp.creation_date,\n                    fp.last_modified,\n                    IF(fp.creation_date = fp.last_modified, 0, 1) is_modified,\n                    fp.post_html,\n\n                    fm.posts_count author_posts_count,\n\n                    a.id     author_id,\n                    a.login  author_login,\n                    a.avatar author_avatar,\n                    ag.name  author_group_name\n\n                FROM forum_posts fp\n                INNER JOIN forum_members fm\n                    ON fm.author_id = fp.authored_by\n                LEFT JOIN members a\n                    ON a.id = fm.author_id\n                LEFT JOIN groups ag\n                    ON ag.id = a.group_id\n                WHERE fp.topic_id = :topic_id\n                ORDER BY fp.topic_start DESC, fp.creation_date ASC\n                LIMIT {$offset}, {$limit}\n            ", array(':topic_id' => $topicID))->fetchAll(\PDO::FETCH_OBJ);
     $hCnf = \App::getConfig('hosts');
     $mCnf = \App::getConfig('member-defaults');
     foreach ($topicPosts as $item) {
         if (!$item->author_avatar) {
             $item->author_avatar = '//' . $hCnf->st . $mCnf->avatar;
         }
     }
     return $topicPosts;
 }
Exemplo n.º 17
0
 /**
  * @covers ::__construct
  * @covers ::registerAlias
  * @depends testGetConfig
  * @depends testGetLocator
  */
 public function testConstructWithArgs()
 {
     $configMockClass = get_class($this->configMock);
     $locatorMockClass = get_class($this->locatorMock);
     $class = $this->testedClass;
     $customtestObj = new $class($configMockClass, $locatorMockClass);
     $this->assertTrue($this->readAttribute($customtestObj, 'instance') instanceof $class);
     $this->assertTrue($customtestObj->getConfig() instanceof $configMockClass);
     $this->assertEquals($customtestObj->getConfig(), \App::getConfig());
     $this->assertTrue($customtestObj->getLocator() instanceof $locatorMockClass);
     $this->assertEquals($customtestObj->getLocator(), \App::getLocator());
 }
Exemplo n.º 18
0
 public function testLog()
 {
     $logPath = App::getConfig('log_path', null);
     $this->assertNotEquals(null, $logPath, "log_path is not defined in config");
     $logFileName = '_test.log_';
     $logFile = $logPath . DIRECTORY_SEPARATOR . $logFileName;
     if (file_exists($logFile)) {
         unlink($logFile);
     }
     App::log('hello', $logFileName);
     $this->assertFileExists($logFile, "Cannot create log file: {$logFile}");
     unlink($logFile);
 }
Exemplo n.º 19
0
 /**
  *  访问端口
  * @return type
  */
 public static function getServerPort()
 {
     $port = App::getConfig('YUC_LOCAL_PORT');
     if (trim($port) == '') {
         return intval($_SERVER['SERVER_PORT']);
     } else {
         $port = intval($port);
         if ($port == 0) {
             return intval($_SERVER['SERVER_PORT']);
         } else {
             return $port;
         }
     }
 }
Exemplo n.º 20
0
 /**
  * __construct
  *
  * Create exception with report data
  *
  * @param  array $report Report data
  * @return null
  */
 public function __construct(array $report)
 {
     $this->_report = $report;
     if (!array_key_exists('code', $this->_report)) {
         $this->_report['code'] = 0;
     }
     $this->_report['initiator_id'] = Member::getProfile()->id;
     $this->_report['type'] = $this->_type;
     $this->_report['file'] = $this->file;
     $this->_report['line'] = $this->line;
     $this->_report['trace'] = parent::getTrace();
     if (App::getConfig('main')->system->write_log) {
         Logger::writeItem($this->_report);
     }
 }
Exemplo n.º 21
0
 function __construct(App $app, $class)
 {
     $this->class = $class;
     $this->metadata = static::getClassAnnotation($class);
     if (!isset($this->metadata['ORM_Entity'])) {
         throw new \Exception('Class ' . $class . ' is not mapped with ORM!');
     }
     //$this->propertiesMetadata = static::getPropertiesMetadata($class);
     $this->table = $this->metadata['ORM_Table'];
     $this->primary = static::findPrimaryProperty($class);
     $this->provider = $app->getConfig()['db']['provider'];
     $this->app = $app;
     $this->toDelete = array();
     $this->entities = array();
     $this->connect();
 }
Exemplo n.º 22
0
	public function dispatchLoopStartup($request)
	{
		$view = Zend_Controller_Action_HelperBroker::getExistingHelper('viewRenderer')->view;
		$device = $view->getHelper('userAgent')->getUserAgent()->getDevice();
		if($device instanceof Zend_Http_UserAgent_Mobile){
			//reset view script base path
			$config = App::getConfig();
			$config['template']['defaulttheme'] = $config['template']['defaultmobiletheme'];
			$config['template']['defaultskin'] = $config['template']['defaultmobileskin'];
			App::setConfig($config);
			
			//reset layout script base path
			$layout = Zend_Layout::getMvcInstance();
            $layout->setViewScriptPath(APPLICATION_PATH.'/design/frontend/'.$config['template']['defaultmobilelayout'].'/layout/');
		}
	}
Exemplo n.º 23
0
 public static function getInstance()
 {
     if (!self::$instance) {
         try {
             $configuration = new \Doctrine\DBAL\Configuration();
             $configuration->setSQLLogger(new \Doctrine\DBAL\Logging\ProfileSQLLogger());
             self::$instance = \Doctrine\DBAL\DriverManager::getConnection(App::getConfig('database'), $configuration);
             self::$instance->query('set names "utf8"');
             self::$instance->query('set character_set_server="utf8"');
             self::$instance->query('set collation_connection="utf8_general_ci"');
         } catch (\PDOException $e) {
             require_once ROOTPATH . 'design' . DS . 'error.php';
             die;
         }
     }
     return self::$instance;
 }
Exemplo n.º 24
0
 /**
  * indexAction
  *
  * Index action of tracker controller forum module
  *
  * @return null
  */
 public function indexAction()
 {
     \View::addLanguageItem('forumTrackerController');
     // validate request params
     $gtfFilter = new \modules\forum\forms\GetTrackerFilter();
     $gtfFilter->validate();
     // invalid request params
     if (!$gtfFilter->isValid()) {
         throw new \SystemErrorException(array('title' => \View::$language->forum_tracker_error, 'description' => \View::$language->forum_tracker_request_invalid));
     }
     // get request data
     $gtfData = $gtfFilter->getData();
     // get limit settings
     $gtfData->limit = \App::getConfig('forum')->topics_per_page;
     // TODO topics per page from member custom settings
     // calculate offset
     $gtfData->offset = ($gtfData->page - 1) * $gtfData->limit;
     // get tracker topics by filter type
     $topics = helpers\TrackerTopicsHelper::getTopics($gtfData->by, $gtfData->offset, $gtfData->limit);
     if ($gtfData->page > 1 && !$topics) {
         throw new \MemberErrorException(array('code' => 404, 'title' => \View::$language->forum_tracker_error, 'description' => \View::$language->forum_tracker_page_not_found));
     }
     // normalize tracker filter url
     $trackerUrl = '/forum/tracker';
     $filterUrl = $trackerUrl;
     if ($gtfData->by != 'last') {
         $filterUrl = '/forum/tracker?by=' . $gtfData->by;
     }
     // get posts pagination
     $pagination = array();
     $allTopicsCnt = helpers\TrackerTopicsHelper::getAllTopicsCount();
     if ($allTopicsCnt > $gtfData->limit) {
         $pagination = \common\PaginationHelper::getItems($filterUrl, $gtfData->page, $gtfData->limit, $allTopicsCnt);
     }
     // normalize tracker filter title
     $filterTitle = 'forum_tracker_by_' . $gtfData->by . '_title';
     $filterTitle = \View::$language->{$filterTitle};
     // append breadcrumbs
     \common\BreadCrumbs::appendItems(array(new \common\BreadCrumbsItem($trackerUrl, \View::$language->forum_tracker_breadcrumbs_name), new \common\BreadCrumbsItem(null, $filterTitle)));
     // assign data into view
     $filters = helpers\TrackerFilterLinksHelper::getLinks($gtfData->by);
     \View::assign(array('title' => $filterTitle, 'filters' => $filters, 'topics' => $topics, 'pagination' => $pagination));
     // set output layout
     \View::setLayout('forum-tracker.phtml');
 }
Exemplo n.º 25
0
 public function __construct()
 {
     if (App::getConfig('YUC_IS_DEBUG')) {
         if (version_compare(PHP_VERSION, '5.0', '>=')) {
             error_reporting(E_ALL & ~E_STRICT);
         } else {
             error_reporting(E_ALL);
         }
         @ini_set('display_errors', 1);
     } else {
         error_reporting(0);
         //? E_ERROR | E_WARNING | E_PARSE
         @ini_set('display_errors', 0);
     }
     //捕获未定义的异常
     set_error_handler(array('App', 'comError'));
     set_exception_handler(array('App', 'comException'));
 }
Exemplo n.º 26
0
 public function __construct($route, array $data)
 {
     $this->config = App::getConfig();
     $this->route = $route;
     $this->language = isset($data['lang']) === true ? $data['lang'] : $this->config->get('lang');
     if (false === empty($data['block'])) {
         $this->block = $data['block'];
     }
     if (true === isset($data['title'])) {
         $this->title = $data['title'];
     }
     if (true === isset($data['description'])) {
         $this->title = $data['description'];
     }
     if (true === isset($data['keywords'])) {
         $this->title = (array) $data['keywords'];
     }
 }
Exemplo n.º 27
0
 /**
  * 获取日志文件路径
  * @param string $dest
  * @return string
  */
 private static function getFile($dest = "")
 {
     if ($dest == '') {
         $dest = M_PRO_DIR . '/Runtime/Log/' . str_replace("_", "", date('Y_m_d')) . '.log.php';
     }
     if (!file_exists($dest)) {
         file_put_contents($dest, "<?php die('Access Defined!');?>\r\n", FILE_APPEND);
     } else {
         if (file_exists($dest)) {
             $size = filesize($dest);
             if ($size >= floor(App::getConfig('YUC_LOG_SIZE'))) {
                 $new = dirname($dest) . '/' . time() . '-' . basename($dest);
                 if (!file_exists($new)) {
                     rename($dest, $new);
                 }
             }
         }
     }
     return $dest;
 }
Exemplo n.º 28
0
 /**
  *  获取校验结果
  * @param $ssid
  * @param $result
  * @param int $diff
  * @return type
  */
 public static function sendVerifyRemoteRequest($ssid, $result, $diff = 0)
 {
     $client = new HttpClient(App::getConfig('YUC_SERVICE_NAME'), App::getConfig('YUC_SERVICE_PORT'));
     $client->setTimeout(App::getConfig('YUC_CLIENT_TIMEOUT'));
     //设置超时
     $client->post(App::getConfig('YUC_VERIFY_PATH'), array('site_key' => App::getConfig('YUC_SITE_KEY'), 'ssid' => $ssid, 'result' => $result, 'diffsec_client' => $diff));
     $post_req = json_decode($client->getContent(), TRUE);
     Log::Write('远程验证完成,输入结果为:' . $result . ',返回状态 :' . $client->getStatus() . ';' . 'POST 验证码正确性请求返回的数据:' . $client->getContent(), Log::DEBUG);
     if ($client->getStatus() == 200 && is_array($post_req)) {
         //200状态 正常返回数据 且返回数据格式正常
         self::$_yuc_code = $post_req['code'];
         self::$_yuc_details = $post_req['details'];
         self::$_yuc_result = $post_req['result'];
     } else {
         self::$_yuc_code = 'E_SEVERVALID_001';
         self::$_yuc_details = '服务器请求失败!';
         self::$_yuc_result = 0;
     }
     return array('code' => self::$_yuc_code, 'result' => self::$_yuc_result, 'details' => self::$_yuc_details);
 }
	public function _($text)
	{
		//get current block module name
		$ws = explode('_', get_class($this));
		$module = strtolower($ws[0]);
		
		if(!Zend_Registry::isRegistered('Zend_Translate')){
			$config = App::getConfig();
			$language = $config['resources']['locale']['default'];
			//@todo add module tranlation files
			$translate = new Zend_Translate(
								array('adapter' => 'csv', 
									  'content' => APPLICATION_PATH.'/design/frontend/'.$config['template']['defaulttheme']."/locale/$language/$module.csv",
									  'delimiter' => ','));
			//@todo add cache
			Zend_Registry::set('Zend_Translate', $translate);
		}
		$translate = Zend_Registry::get('Zend_Translate');
		return $translate->_($text);
	}
Exemplo n.º 30
0
 /**
  * trySignIn
  *
  * Try sign in process
  *
  * @param  StdClass $signInData Member sign in data
  * @return null
  */
 public static function trySignIn(\StdClass $signInData)
 {
     \View::addLanguageItem('SignInHelper');
     $memberData = \DBI::getConnection('master')->sendQuery('SELECT cookie, password, status
             FROM members
             WHERE email = :email OR login = :login', array(':email' => $signInData->login, ':login' => $signInData->login))->fetch(\PDO::FETCH_OBJ);
     // member data not found
     if (!$memberData) {
         throw new \MemberErrorException(array('title' => \View::$language->sign_in_helper_error, 'description' => \View::$language->sign_in_helper_login_or_password_invalid));
     }
     // compare password
     $hasSamePassword = \common\CryptHelper::verifyHash($signInData->password, $memberData->password);
     if (!$hasSamePassword) {
         throw new \MemberErrorException(array('title' => \View::$language->sign_in_helper_error, 'description' => \View::$language->sign_in_helper_login_or_password_invalid));
     }
     // sign in success
     $cnf = \App::getConfig('main')->system;
     $exp = time() + $cnf->cookie_expires_time;
     setcookie($cnf->cookie_name, $memberData->cookie, $exp, '/');
     throw new \MemberSuccessException(array('title' => \View::$language->sign_in_helper_success, 'description' => \View::$language->sign_in_helper_success_description, 'redirection' => '/'));
 }