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

Commit

Permalink
Issue #56 - Changed to pull profile picture each time the user logs in
Browse files Browse the repository at this point in the history
  • Loading branch information
pbrenner committed Mar 12, 2013
1 parent 1eec296 commit 6ac2576
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion app/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ private function _initUser() {


if ($user) {
$this->_currentUser = $user;
//$this->_currentUser = $user;
// Update the user record with the new image
$this->_currentUser = $this->_updateUser($user, $facebookId);

} else {
$this->_currentUser = $this->_createUser($facebookId);
}
Expand Down Expand Up @@ -184,6 +187,43 @@ private function _createUser($facebookId){

return $data;
}

/**
* Update the user record with an updated profile picture
*
* TODO: Need error trapping here badly
*
* @author khoople
*
* @param int $facebookId
* @return array
*/
private function _updateUser($user, $facebookId) {
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://graph.facebook.com/$facebookId/picture?type=large");

curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);

$url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);

curl_close($ch);

$data['User'] = array(
'image' => $url,
'id' => $user['User']['id']
);

// Create the new user
$this->User->Save($data);

return $this->User->findById($user['User']['id']);

}

/**
* Redirect user to the page where they grant access to our facebook app.
Expand Down

0 comments on commit 6ac2576

Please sign in to comment.