Skip to content
This repository has been archived by the owner on May 28, 2020. It is now read-only.

Commit

Permalink
Issue #12 - Facebook logout
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Brenner <peter@phpwerks.com>
  • Loading branch information
pbrenner committed Feb 18, 2013
1 parent df48108 commit 0bdfefe
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
14 changes: 13 additions & 1 deletion app/Controller/AppController.php
Expand Up @@ -93,13 +93,25 @@ private function _initUser() {
$this->_initFacebook();
$facebookId = $this->_facebook->getUser();


// If can't get facebook uid, they must accept the app and/or login

//CPB
if (!$facebookId) {
$this->_redirectToLoginUrl();
} else {
// make sure the user is still logged in
try {
$me = $this->_facebook->api('/me');
if ($me) {
//User is logged in
}
} catch (FacebookApiException $e) {
//User is not logged in
$this->_redirectToLoginUrl();
}

}

$this->loadModel('User');

$user = $this->User->findByFacebookId($facebookId);
Expand Down
4 changes: 3 additions & 1 deletion app/Controller/ElectionsController.php
Expand Up @@ -36,6 +36,8 @@ public function view($id = null) {
throw new NotFoundException(__('Invalid election'));
}
//$this->set('election', $this->Election->read(null, $id));

$offices = $this->Election->Office->find('all', array('conditions' => array('election_id' => $id)));

$election = $this->Election->read(null, $id);
$electionID = $id;
Expand All @@ -46,7 +48,7 @@ public function view($id = null) {
$allConstituencies = $this->Election->Candidate->find('all', array('conditions' => array('Candidate.user_id' => $this->_currentUser['User']['id']),
'recursive' => 2));

$this->set(compact('callback','election', 'electionID', 'constituentID', 'officeID', 'allConstituencies'));
$this->set(compact('callback','election', 'electionID', 'constituentID', 'officeID', 'allConstituencies', 'offices'));

//$this->redirect(array('controller' => 'constituencies', 'action' => 'index', 'home'));
}
Expand Down
32 changes: 24 additions & 8 deletions app/Vendor/facebook/base_facebook.php
Expand Up @@ -120,7 +120,7 @@ abstract class BaseFacebook
/**
* Version.
*/
const VERSION = '3.2.0';
const VERSION = '3.2.2';

/**
* Signed Request Algorithm.
Expand Down Expand Up @@ -367,20 +367,20 @@ public function setExtendedAccessToken() {
// In any event, we don't have an access token, so say so.
return false;
}

if (empty($access_token_response)) {
return false;
}

$response_params = array();
parse_str($access_token_response, $response_params);

if (!isset($response_params['access_token'])) {
return false;
}

$this->destroySession();

$this->setPersistentData(
'access_token', $response_params['access_token']
);
Expand Down Expand Up @@ -439,6 +439,11 @@ protected function getUserAccessToken() {
// the JS SDK puts a code in with the redirect_uri of ''
if (array_key_exists('code', $signed_request)) {
$code = $signed_request['code'];
if ($code && $code == $this->getPersistentData('code')) {
// short-circuit if the code we have is the same as the one presented
return $this->getPersistentData('access_token');
}

$access_token = $this->getAccessTokenFromCode($code, '');
if ($access_token) {
$this->setPersistentData('code', $code);
Expand Down Expand Up @@ -483,10 +488,10 @@ protected function getUserAccessToken() {
*/
public function getSignedRequest() {
if (!$this->signedRequest) {
if (isset($_REQUEST['signed_request'])) {
if (!empty($_REQUEST['signed_request'])) {
$this->signedRequest = $this->parseSignedRequest(
$_REQUEST['signed_request']);
} else if (isset($_COOKIE[$this->getSignedRequestCookieName()])) {
} else if (!empty($_COOKIE[$this->getSignedRequestCookieName()])) {
$this->signedRequest = $this->parseSignedRequest(
$_COOKIE[$this->getSignedRequestCookieName()]);
}
Expand Down Expand Up @@ -524,6 +529,11 @@ protected function getUserFromAvailableData() {
if ($signed_request) {
if (array_key_exists('user_id', $signed_request)) {
$user = $signed_request['user_id'];

if($user != $this->getPersistentData('user_id')){
$this->clearAllPersistentData();
}

$this->setPersistentData('user_id', $signed_request['user_id']);
return $user;
}
Expand Down Expand Up @@ -1143,10 +1153,16 @@ protected function getHttpProtocol() {
}
return 'http';
}
/*apache + variants specific way of checking for https*/
if (isset($_SERVER['HTTPS']) &&
($_SERVER['HTTPS'] === 'on' || $_SERVER['HTTPS'] == 1)) {
return 'https';
}
/*nginx way of checking for https*/
if (isset($_SERVER['SERVER_PORT']) &&
($_SERVER['SERVER_PORT'] === '443')) {
return 'https';
}
return 'http';
}

Expand Down

0 comments on commit 0bdfefe

Please sign in to comment.