function weiboCallback($type, $lastkey) { if ($lastkey) { $last_key = $lastkey; } else { $last_key = AuthCallback($type); } if ($last_key) { // 如果成功取得last_key $db =& JFactory::getDBO(); // 先将数据库中原有数据无论有无均删除 $sql = "DELETE FROM #__weibo_auth WHERE type='" . $type . "'"; $db->setQuery($sql); $db->Query(); // 将取得的last_key写入数据库中 $sql = "INSERT INTO #__weibo_auth(oauth_token,oauth_token_secret,name,type ) VALUES ('{$last_key['oauth_token']}','{$last_key['oauth_token_secret']}','{$last_key['user_id']}','{$type}') "; $db->setQuery($sql); $db->Query(); // 显示已经成功获得授权的页面 if (!$lastkey) { HTML_weibo::finishedWeiboAuth($last_key, $type); } } else { // 如果未成功取得last_key,显示出错的页面 HTML_weibo::errorWeiboAuth($last_key, $type); } }
function authlogin($type) { $zhtype = TypeCheck($type); $document = JFactory::getDocument(); $viewType = $document->getType(); $viewLayout = JRequest::getCmd('layout', 'default'); if (version_compare(JVERSION, '1.6.0', 'ge')) { // Joomla! 1.7 $viewName = $this->default_view; $view = $this->getView($viewName, $viewType, '', array('base_path' => $this->basePath)); } else { // Joomla! 1.5 $viewName = JRequest::getCmd('view'); $view = $this->getView($viewName, $viewType); } $view->return = JRequest::getCmd('rid'); // 这里准备一套假的用户名与密码,以备后面的认证插件认证不通过 $view->showusername = '******'; $view->showpassword = '******'; $_SESSION['weibouserlogin'] = 0; $last_key = AuthCallback($type); if ($last_key) { // 如果认证通过,以"用户ID@xxxxxweibo" 为joomla中的用户名 if ($type == 'qq') { $view->showusername = $last_key['user_id'] . '@' . $type; } else { $view->showusername = $last_key['user_id'] . '@' . $type . 'weibo'; } $view->showpassword = base64_encode($view->showusername); // 以“用户昵称(来自某某微博)”用户昵称 $_SESSION['weibousername'] = $last_key['user_name'] . '(来自' . $zhtype . ')'; if (array_key_exists('user_email', $last_key)) { $_SESSION['weibouseremail'] = $last_key['user_email']; } else { unset($_SESSION['weibouseremail']); } $_SESSION['weibouserlogin'] = 1; $view->weibologin(); } else { $view->weibologinerror($type, $zhtype); } return $this; }