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

Commit 6ac2576

Browse files
committed
Issue #56 - Changed to pull profile picture each time the user logs in
1 parent 1eec296 commit 6ac2576

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

app/Controller/AppController.php

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ private function _initUser() {
118118

119119

120120
if ($user) {
121-
$this->_currentUser = $user;
121+
//$this->_currentUser = $user;
122+
// Update the user record with the new image
123+
$this->_currentUser = $this->_updateUser($user, $facebookId);
124+
122125
} else {
123126
$this->_currentUser = $this->_createUser($facebookId);
124127
}
@@ -184,6 +187,43 @@ private function _createUser($facebookId){
184187

185188
return $data;
186189
}
190+
191+
/**
192+
* Update the user record with an updated profile picture
193+
*
194+
* TODO: Need error trapping here badly
195+
*
196+
* @author khoople
197+
*
198+
* @param int $facebookId
199+
* @return array
200+
*/
201+
private function _updateUser($user, $facebookId) {
202+
$ch = curl_init();
203+
204+
curl_setopt($ch, CURLOPT_URL, "http://graph.facebook.com/$facebookId/picture?type=large");
205+
206+
curl_setopt($ch, CURLOPT_HEADER, false);
207+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
208+
curl_setopt($ch, CURLOPT_NOBODY, true);
209+
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
210+
curl_exec($ch);
211+
212+
$url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
213+
214+
curl_close($ch);
215+
216+
$data['User'] = array(
217+
'image' => $url,
218+
'id' => $user['User']['id']
219+
);
220+
221+
// Create the new user
222+
$this->User->Save($data);
223+
224+
return $this->User->findById($user['User']['id']);
225+
226+
}
187227

188228
/**
189229
* Redirect user to the page where they grant access to our facebook app.

0 commit comments

Comments
 (0)