0
我無法登錄我的php facebook會話用戶。這裏是我當前的代碼:Facebook沒有註銷
public function facebookAction()
{
if(isset(Core::session('FacebookAuthSession')->sessionObject)){
// $oldFetchmode = Core::db()->getFetchMode();
// Core::db()->setFetchMode(Zend_Db::FETCH_OBJ);
// $userObj = new Core_Model_User();
// $facebookUid = Core::session('FacebookAuthSession')->graphObject->backingData['id'];
// $sel = $userObj->select();
// $sel->where('fuid=:fuid')->bind(array("fuid"=>$facebookUid));
// $data = $userObj->fetchRow();
// $userId = $data->id;
// Core::db()->setFetchMode($oldFetchmode);
// Ranger_Application_Util::logUserIn($userId);
//Core::dump(Core::session('FacebookAuthSession'));
//die();
Ranger_Application_Util::redirectToAppUrl('/app/home');
} else {
FacebookSession::setDefaultApplication('xxx', 'xxx');
$helper = new FacebookRedirectLoginHelper('http://jobrangers.com/newhomepage/html/en/auth/facebooklogin');
$loginUrl = $helper->getLoginUrl();
$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper ('Redirector');
$redirector->gotoUrl ($loginUrl)->redirectAndExit();
}
}
public function facebookloginAction()
{
FacebookSession::setDefaultApplication('xxx', 'xxx');
$helper = new FacebookRedirectLoginHelper('http://jobrangers.com/newhomepage/html/en/auth/facebooklogin');
$session = null;
try {
$session = $helper->getSessionFromRedirect();
Core::session('FacebookAuthSession')->sessionObject = $session;
} catch(FacebookRequestException $ex) {
} catch(\Exception $ex) {
}
$request = new FacebookRequest($session, 'GET', '/me');
$response = $request->execute();
$graphObject = $response->getGraphObject();
Core::session('FacebookAuthSession')->graphObject = $graphObject;
$oldFetchmode = Core::db()->getFetchMode();
Core::db()->setFetchMode(Zend_Db::FETCH_OBJ);
$userObj = new Core_Model_Resource_Users();
$backingData = Core::session('FacebookAuthSession')->graphObject->asArray();
$facebookUid = $backingData['id'];
$sel = $userObj->select();
$sel->where('fuid=:fuid')->bind(array("fuid"=>$facebookUid));
$data = $userObj->fetchRow();
Core::db()->setFetchMode($oldFetchmode);
if($data){
$userId = $data->id;
} else {
$data = array();
$data['date_created'] = new Zend_Db_Expr("NOW()");
$data['date_updated'] = new Zend_Db_Expr("NOW()");
$data['fuid'] = $facebookUid;
$data['first_name'] = $backingData['first_name'];
$data['last_name'] = $backingData['last_name'];
$userId = $userObj->insert($data);
}
Ranger_Application_Util::logUserIn($userId);
}
的數據被保存在一個Zend_Session_Namespace
(Core::session('FacebookAuthSession')
)
這裏是我的註銷代碼:
public function logoutAction() {
$username = Ranger_Application_Util::getStorageData('username');
Core::log ("User $username logged out.", Zend_Log::INFO);
Ranger_Application_Util::makeUserOffline (Ranger_Application_Util::getStorageData ('id'));
Zend_Auth::getInstance()->clearIdentity();
$_SESSION = array();
Zend_Session::destroy();
Core::session('FacebookAuthSession')->unsetAll();
$_COOKIE = array();
$locale = Core::registry ('Zend_Locale');
$this->_redirect ('/' . $locale->getLanguage() );
}
我嘗試刪除所有會話的會話目錄。我還使用了Zend_Session::destroy()
和Core::session('FacebookAuthSession')->unsetAll()
,它應該取消設置FacebookAuthSession Namespace
中的數據。我不太明白,但它只是回到app home
。