} else {
// save it as an avatar
- $file = new ImageFile($user->id, Avatar::path($tmpname));
- $filename = $file->resize(180); // size of the biggest img we get from Facebook
+ $imagefile = new ImageFile(null, Avatar::path($tmpname));
+ $filename = Avatar::filename($user->id, image_type_to_extension($imagefile->preferredType()),
+ 180, common_timestamp());
+ // Previous docs said 180 is the "biggest img we get from Facebook"
+ $imagefile->resizeTo(Avatar::path($filename, array('width'=>180, 'height'=>180)));
+
+ // No need to keep the temporary file around...
+ @unlink(Avatar::path($tmpname));
$profile = $user->getProfile();
);
// clean up tmp file
- @unlink(Avatar::path($tmpname));
}
}
function tryLogin()
{
- $flink = Foreign_link::getByForeignID($this->fbuid, FACEBOOK_SERVICE);
-
- if (!empty($flink)) {
+ try {
+ $flink = Foreign_link::getByForeignID($this->fbuid, FACEBOOK_SERVICE);
$user = $flink->getUser();
- if (!empty($user)) {
-
- common_log(
- LOG_INFO,
- sprintf(
- 'Logged in Facebook user %s as user %d (%s)',
- $this->fbuid,
- $user->nickname,
- $user->id
- ),
- __FILE__
- );
+ common_log(
+ LOG_INFO,
+ sprintf(
+ 'Logged in Facebook user %s as user %d (%s)',
+ $this->fbuid,
+ $user->nickname,
+ $user->id
+ ),
+ __FILE__
+ );
- common_set_user($user);
- common_real_login(true);
+ common_set_user($user);
+ common_real_login(true);
- // clear out the stupid cookie
- setcookie('fb_access_token', '', time() - 3600); // one hour ago
+ // clear out the stupid cookie
+ setcookie('fb_access_token', '', time() - 3600); // one hour ago
- $this->goHome($user->nickname);
- }
+ $this->goHome($user->nickname);
- } else {
+ } catch (NoResultException $e) {
$this->showForm(null, $this->bestNewNickname());
}
}