/**
  * Handler method
  *
  * @param array $args is ignored since it's now passed in in prepare()
  */
 function handle($args)
 {
     parent::handle($args);
     $data = $this->facebook->getSignedRequest();
     if (isset($data['user_id'])) {
         $fbuid = $data['user_id'];
         $flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE);
         $user = $flink->getUser();
         // Remove the link to Facebook
         $result = $flink->delete();
         if (!$result) {
             common_log_db_error($flink, 'DELETE', __FILE__);
             common_log(LOG_WARNING, sprintf('Unable to delete Facebook foreign link ' . 'for %s (%d), fbuid %d', $user->nickname, $user->id, $fbuid), __FILE__);
             return;
         }
         common_log(LOG_INFO, sprintf('Facebook callback: %s (%d), fbuid %d has deauthorized ' . 'the Facebook application.', $user->nickname, $user->id, $fbuid), __FILE__);
         // Warn the user about being locked out of their account
         // if we can.
         if (empty($user->password) && !empty($user->email)) {
             Facebookclient::emailWarn($user);
         } else {
             common_log(LOG_WARNING, sprintf('%s (%d), fbuid %d has deauthorized his/her Facebook ' . 'connection but hasn\'t set a password so s/he ' . 'is locked out.', $user->nickname, $user->id, $fbuid), __FILE__);
         }
     } else {
         if (!empty($data)) {
             common_log(LOG_WARNING, sprintf('Facebook called the deauthorize callback ' . ' but didn\'t provide a user ID.'), __FILE__);
         } else {
             // It probably wasn't Facebook that hit this action,
             // so redirect to the public timeline
             common_redirect(common_local_url('public'), 303);
         }
     }
 }
 function handle($notice)
 {
     if ($notice->isLocal()) {
         return Facebookclient::facebookBroadcastNotice($notice);
     }
     return true;
 }
示例#3
0
 function showContent()
 {
     $this->elementStart('fieldset');
     $facebook = Facebookclient::getFacebook();
     $params = array('scope' => 'read_stream,publish_stream,offline_access,user_status,user_location,user_website,email', 'redirect_uri' => common_local_url('facebookfinishlogin'));
     // Degrade to plain link if JavaScript is not available
     $this->elementStart('a', array('href' => $facebook->getLoginUrl($params), 'id' => 'facebook_button'));
     $attrs = array('src' => Plugin::staticPath('FacebookBridge', 'images/login-button.png'), 'alt' => _m('Login with Facebook'), 'title' => _m('Login with Facebook.'));
     $this->element('img', $attrs);
     $this->elementEnd('a');
     $this->elementEnd('fieldset');
 }
 function showContent()
 {
     $this->elementStart('fieldset');
     $facebook = Facebookclient::getFacebook();
     // Degrade to plain link if JavaScript is not available
     $this->elementStart('a', array('href' => $facebook->getLoginUrl(array('next' => common_local_url('facebookfinishlogin'), 'cancel' => common_local_url('facebooklogin'), 'req_perms' => 'read_stream,publish_stream,offline_access,user_status,user_location,user_website,email')), 'id' => 'facebook_button'));
     $attrs = array('src' => Plugin::staticPath('FacebookBridge', 'images/login-button.png'), 'alt' => _m('Login with Facebook'), 'title' => _m('Login with Facebook.'));
     $this->element('img', $attrs);
     $this->elementEnd('a');
     /*
     $this->element('div', array('id' => 'fb-root'));
     $this->script(
         sprintf(
             'http://connect.facebook.net/en_US/all.js#appId=%s&xfbml=1',
             common_config('facebook', 'appid')
         )
     );
     $this->element('fb:facepile', array('max-rows' => '2', 'width' =>'300'));
     */
     $this->elementEnd('fieldset');
 }
示例#5
0
 function createNewUser()
 {
     if (!Event::handle('StartRegistrationTry', array($this))) {
         return;
     }
     if (common_config('site', 'closed')) {
         // TRANS: Client error trying to register with registrations not allowed.
         $this->clientError(_m('Registration not allowed.'));
         return;
     }
     $invite = null;
     if (common_config('site', 'inviteonly')) {
         $code = $_SESSION['invitecode'];
         if (empty($code)) {
             // TRANS: Client error trying to register with registrations 'invite only'.
             $this->clientError(_m('Registration not allowed.'));
             return;
         }
         $invite = Invitation::staticGet($code);
         if (empty($invite)) {
             // TRANS: Client error trying to register with an invalid invitation code.
             $this->clientError(_m('Not a valid invitation code.'));
             return;
         }
     }
     try {
         $nickname = Nickname::normalize($this->trimmed('newname'));
     } catch (NicknameException $e) {
         $this->showForm($e->getMessage());
         return;
     }
     if (!User::allowed_nickname($nickname)) {
         // TRANS: Form validation error displayed when picking a nickname that is not allowed.
         $this->showForm(_m('Nickname not allowed.'));
         return;
     }
     if (User::staticGet('nickname', $nickname)) {
         // TRANS: Form validation error displayed when picking a nickname that is already in use.
         $this->showForm(_m('Nickname already in use. Try another one.'));
         return;
     }
     $args = array('nickname' => $nickname, 'fullname' => $this->fbuser->name, 'homepage' => $this->fbuser->website, 'location' => $this->fbuser->location->name);
     // It's possible that the email address is already in our
     // DB. It's a unique key, so we need to check
     if ($this->isNewEmail($this->fbuser->email)) {
         $args['email'] = $this->fbuser->email;
         if (isset($this->fuser->verified) && $this->fuser->verified == true) {
             $args['email_confirmed'] = true;
         }
     }
     if (!empty($invite)) {
         $args['code'] = $invite->code;
     }
     $user = User::register($args);
     $result = $this->flinkUser($user->id, $this->fbuid);
     if (!$result) {
         // TRANS: Server error displayed when connecting to Facebook fails.
         $this->serverError(_m('Error connecting user to Facebook.'));
         return;
     }
     // Add a Foreign_user record
     Facebookclient::addFacebookUser($this->fbuser);
     $this->setAvatar($user);
     common_set_user($user);
     common_real_login(true);
     common_log(LOG_INFO, sprintf('Registered new user %s (%d) from Facebook user %s, (fbuid %d)', $user->nickname, $user->id, $this->fbuser->name, $this->fbuid), __FILE__);
     Event::handle('EndRegistrationTry', array($this));
     $this->goHome($user->nickname);
 }
 /**
  * Notify remote users when their notices get de-favorited.
  *
  * @param Profile $profile Profile person doing the de-faving
  * @param Notice  $notice  Notice being favored
  *
  * @return hook return value
  */
 function onEndDisfavorNotice(Profile $profile, Notice $notice)
 {
     $client = new Facebookclient($notice, $profile);
     $client->unLike();
     return true;
 }
 static function facebookBroadcastNotice($notice)
 {
     $client = new Facebookclient($notice);
     return $client->sendNotice();
 }