/** * 执行函数 * * @access public * @return void */ public function execute() { if ($this->hasLogin()) { $rows = $this->db->fetchAll($this->db->select()->from('table.options')->where('user = ?', $this->_user['uid'])); $this->push($this->_user); foreach ($rows as $row) { $this->options->__set($row['name'], $row['value']); } //更新最后活动时间 $this->db->query($this->db->update('table.users')->rows(array('activated' => $this->options->gmtTime))->where('uid = ?', $this->_user['uid'])); } }
/** * 以用户名和密码登录 * * @access public * @param string $name 用户名 * @param string $password 密码 * @param boolean $temporarily 是否为临时登录 * @param integer $expire 过期时间 * @return boolean */ public function login($name, $password, $temporarily = false, $expire = 0) { //插件接口 $result = $this->pluginHandle()->trigger($loginPluggable)->login($name, $password, $temporarily, $expire); if ($loginPluggable) { return $result; } /** 开始验证用户 **/ $user = $this->db->fetchRow($this->db->select()->from('table.users')->where('name = ?', $name)->limit(1)); $hashValidate = $this->pluginHandle()->trigger($hashPluggable)->hashValidate($password, $user['password']); if (!$hashPluggable) { $hashValidate = Typecho_Common::hashValidate($password, $user['password']); } if ($user && $hashValidate) { if (!$temporarily) { $authCode = sha1(Typecho_Common::randString(20)); $user['authCode'] = $authCode; Typecho_Cookie::set('__typecho_uid', $user['uid'], $expire, $this->options->siteUrl); Typecho_Cookie::set('__typecho_authCode', Typecho_Common::hash($authCode), $expire, $this->options->siteUrl); //更新最后登录时间以及验证码 $this->db->query($this->db->update('table.users')->expression('logged', 'activated')->rows(array('authCode' => $authCode))->where('uid = ?', $user['uid'])); } /** 压入数据 */ $this->push($user); $this->_hasLogin = true; $this->pluginHandle()->loginSucceed($this, $name, $password, $temporarily, $expire); return true; } $this->pluginHandle()->loginFail($this, $name, $password, $temporarily, $expire); return false; }
/** * 执行函数 * * @access public * @return void */ public function execute() { $this->db->fetchAll($this->db->select()->from('table.options')->where('user = 0'), array($this, 'push')); /** 支持皮肤变量重载 */ if (!empty($this->row['theme:' . $this->row['theme']])) { $themeOptions = NULL; /** 解析变量 */ if ($themeOptions = unserialize($this->row['theme:' . $this->row['theme']])) { /** 覆盖变量 */ $this->row = array_merge($this->row, $themeOptions); } } $this->stack[] =& $this->row; /** 初始化站点信息 */ $this->siteUrl = Typecho_Common::url(NULL, $this->siteUrl); $this->plugins = unserialize($this->plugins); /** 增加对SSL连接的支持 */ if ($this->request->isSecure() && 0 === strpos($this->siteUrl, 'http://')) { $this->siteUrl = substr_replace($this->siteUrl, 'https', 0, 4); } /** 自动初始化路由表 */ $this->routingTable = unserialize($this->routingTable); if (!isset($this->routingTable[0])) { /** 解析路由并缓存 */ $parser = new Typecho_Router_Parser($this->routingTable); $parsedRoutingTable = $parser->parse(); $this->routingTable = array_merge(array($parsedRoutingTable), $this->routingTable); $this->db->query($this->db->update('table.options')->rows(array('value' => serialize($this->routingTable)))->where('name = ?', 'routingTable')); } }
/** * 执行函数 * * @access public * @return void */ public function execute() { $this->db->fetchAll($this->db->select()->from('table.options')->where('user = 0'), array($this, 'push')); /** 支持皮肤变量重载 */ if (!empty($this->row['theme:' . $this->row['theme']])) { $themeOptions = NULL; /** 解析变量 */ if ($themeOptions = unserialize($this->row['theme:' . $this->row['theme']])) { /** 覆盖变量 */ $this->row = array_merge($this->row, $themeOptions); } } $this->stack[] =& $this->row; /** 初始化站点信息 */ if (defined('__TYPECHO_SITE_URL__')) { $this->siteUrl = __TYPECHO_SITE_URL__; } $this->originalSiteUrl = $this->siteUrl; $this->siteUrl = Typecho_Common::url(NULL, $this->siteUrl); $this->plugins = unserialize($this->plugins); /** 动态判断皮肤目录 */ $this->theme = is_dir($this->themeFile($this->theme)) ? $this->theme : 'default'; /** 动态获取根目录 */ $this->rootUrl = $this->request->getRequestRoot(); if (defined('__TYPECHO_ADMIN__')) { $adminDir = '/' . trim(defined('__TYPECHO_ADMIN_DIR__') ? __TYPECHO_ADMIN_DIR__ : '/admin/', '/'); $this->rootUrl = substr($this->rootUrl, 0, -strlen($adminDir)); } /** 增加对SSL连接的支持 */ if ($this->request->isSecure() && 0 === strpos($this->siteUrl, 'http://')) { $this->siteUrl = substr_replace($this->siteUrl, 'https', 0, 4); } //$router = include __TYPECHO_ROOT_DIR__.'/var/config.php'; //$parser = new Typecho_Router_Parser($router); //$parsedRoutingTable = $parser->parse(); //$this->routingTable = array($parsedRoutingTable); /** 自动初始化路由表 */ $this->routingTable = unserialize($this->routingTable); if (!isset($this->routingTable[0])) { /** 解析路由并缓存 */ $parser = new Typecho_Router_Parser($this->routingTable); $parsedRoutingTable = $parser->parse(); $this->routingTable = array_merge(array($parsedRoutingTable), $this->routingTable); $this->db->query($this->db->update('table.options')->rows(array('value' => serialize($this->routingTable)))->where('name = ?', 'routingTable')); } }
/** * 以用户名和密码登录 * * @access public * @param string $name 用户名 * @param string $password 密码 * @param boolean $temporarily 是否为临时登录 * @param integer $expire 过期时间 * @return boolean */ public function login($name, $password, $temporarily = false, $expire = 0) { //插件接口 $result = $this->pluginHandle()->trigger($loginPluggable)->login($name, $password, $temporarily, $expire); if ($loginPluggable) { return $result; } /** 开始验证用户 **/ $user = $this->db->fetchRow($this->db->select()->from('table.users')->where((strpos($name, '@') ? 'mail' : 'name') . ' = ?', $name)->limit(1)); if (empty($user)) { return false; } $hashValidate = $this->pluginHandle()->trigger($hashPluggable)->hashValidate($password, $user['password']); if (!$hashPluggable) { if ('$P$' == substr($user['password'], 0, 3)) { $hasher = new PasswordHash(8, true); $hashValidate = $hasher->CheckPassword($password, $user['password']); } else { $hashValidate = Typecho_Common::hashValidate($password, $user['password']); } } if ($user && $hashValidate) { if (!$temporarily) { $authCode = function_exists('openssl_random_pseudo_bytes') ? bin2hex(openssl_random_pseudo_bytes(16)) : sha1(Typecho_Common::randString(20)); $user['authCode'] = $authCode; Typecho_Cookie::set('__typecho_uid', $user['uid'], $expire); Typecho_Cookie::set('__typecho_authCode', Typecho_Common::hash($authCode), $expire); //更新最后登录时间以及验证码 $this->db->query($this->db->update('table.users')->expression('logged', 'activated')->rows(array('authCode' => $authCode))->where('uid = ?', $user['uid'])); } /** 压入数据 */ $this->push($user); $this->_hasLogin = true; $this->pluginHandle()->loginSucceed($this, $name, $password, $temporarily, $expire); return true; } $this->pluginHandle()->loginFail($this, $name, $password, $temporarily, $expire); return false; }
/** * 升级至10.2.27 * * @access public * @param Typecho_Db $db 数据库对象 * @param Typecho_Widget $options 全局信息组件 * @return void */ public static function v0_8r10_2_27($db, $options) { /** 增加若干选项 */ $db->query($db->insert('table.options')->rows(array('name' => 'commentsAvatar', 'user' => 0, 'value' => 1))); $db->query($db->insert('table.options')->rows(array('name' => 'commentsAvatarRating', 'user' => 0, 'value' => 'G'))); //更新扩展 if (NULL != $options->attachmentTypes) { $attachmentTypes = array_map('trim', explode(';', $options->attachmentTypes)); $attachmentTypesResult = array(); foreach ($attachmentTypes as $type) { $type = trim($type, '*.'); if (!empty($type)) { $attachmentTypesResult[] = $type; } } if (!empty($attachmentTypesResult)) { $db->query($db->update('table.options')->rows(array('value' => implode(',', $attachmentTypesResult)))->where('name = ?', 'attachmentTypes')); } } }
$dbPrefix = $config['prefix']; $tableArray = array($dbPrefix . 'comments', $dbPrefix . 'contents', $dbPrefix . 'fields', $dbPrefix . 'metas', $dbPrefix . 'options', $dbPrefix . 'relationships', $dbPrefix . 'users'); foreach ($tableArray as $table) { if ($type == 'Mysql') { $installDb->query("DROP TABLE IF EXISTS `{$table}`"); } elseif ($type == 'Pgsql') { $installDb->query("DROP TABLE {$table}"); } elseif ($type == 'SQLite') { $installDb->query("DROP TABLE {$table}"); } } echo '<p class="message success">' . _t('已经删除完原有数据') . '<br /><br /><button type="submit" class="primary">' . _t('继续安装 »') . '</button></p>'; } elseif (_r('goahead')) { //使用原有数据 //但是要更新用户网站 $installDb->query($installDb->update('table.options')->rows(array('value' => $config['siteUrl']))->where('name = ?', 'siteUrl')); unset($_SESSION['typecho']); Typecho_Cookie::delete('__typecho_config'); header('Location: ./install.php?finish&use_old'); exit; } else { echo '<p class="message error">' . _t('安装程序检查到原有数据表已经存在.') . '<br /><br />' . '<button type="submit" name="delete" value="1" class="btn-warn">' . _t('删除原有数据') . '</button> ' . _t('或者') . ' <button type="submit" name="goahead" value="1" class="primary">' . _t('使用原有数据') . '</button></p>'; } } else { echo '<p class="message error">' . _t('安装程序捕捉到以下错误: "%s". 程序被终止, 请检查您的配置信息.', $e->getMessage()) . '</p>'; } ?> </form> </div> <?php }
$dbPrefix = _r('dbPrefix'); $tableArray = array($dbPrefix . 'comments', $dbPrefix . 'contents', $dbPrefix . 'metas', $dbPrefix . 'options', $dbPrefix . 'relationships', $dbPrefix . 'users'); foreach ($tableArray as $table) { if ($type == 'Mysql') { $installDb->query("DROP TABLE IF EXISTS `{$table}`"); } elseif ($type == 'Pgsql') { $installDb->query("DROP TABLE {$table}"); } elseif ($type == 'SQLite') { $installDb->query("DROP TABLE {$table}"); } } echo '<p class="message success typecho-radius-topleft typecho-radius-topright typecho-radius-bottomleft typecho-radius-bottomright">已经删除完原有数据,请点击继续安装<button type="submit">下一步</button></p>'; } elseif (_r('goahead')) { //使用原有数据 //但是要更新用户网站 $installDb->query($installDb->update('table.options')->rows(array('value' => _r('userUrl')))->where('name = ?', 'siteUrl')); header('Location: install.php?finish&use_old'); exit; } else { echo '<p class="message error typecho-radius-topleft typecho-radius-topright typecho-radius-bottomleft typecho-radius-bottomright">' . _t('安装程序检查到原有数据表已经存在,请先删除该表然后再继续进行安装.') . '您可以选择<button type="submit" name="delete" value="1">删除数据原有数据</button>或者直接<button type="submit" name="goahead" value="1">使用原有数据</button>安装</p>'; } } else { echo '<p class="message error typecho-radius-topleft typecho-radius-topright typecho-radius-bottomleft typecho-radius-bottomright">' . _t('安装程序捕捉到以下错误: "%s". 程序被终止, 请检查您的配置信息.', $e->getMessage()) . '</p>'; } } } if ($success != true && file_exists(__TYPECHO_ROOT_DIR__ . '/config.inc.php')) { unlink(__TYPECHO_ROOT_DIR__ . '/config.inc.php'); } } ?>