Пример #1
0
 /**
  * Gets the meta data for avatar from the OAuth client
  *
  * @author Jason Rey <*****@*****.**>
  * @since  1.2
  * @access public
  * @param  Array		$details The metadata
  * @param  SocialOAuth	$client  The Oauth client class
  */
 public function onOAuthGetUserMeta(&$details, &$client)
 {
     $config = FD::config();
     if ($config->get('oauth.' . $client->getType() . '.registration.cover') && isset($details['cover'])) {
         $cover = new stdClass();
         $cover->url = $details['cover']['source'];
         $cover->offset_y = $details['cover']['offset_y'];
         $details['cover'] = $cover;
     }
 }
Пример #2
0
 /**
  * Gets the meta data for avatar from the OAuth client
  *
  * @author Jason Rey <*****@*****.**>
  * @since  1.2
  * @access public
  * @param  Array		$details The metadata
  * @param  SocialOAuth	$client  The Oauth client class
  */
 public function onOAuthGetUserMeta(&$details, &$client)
 {
     $config = FD::config();
     if ($config->get('oauth.' . $client->getType() . '.registration.avatar')) {
         $avatar = $client->api('me/picture', array('type' => 'large', 'redirect' => false));
         $avatarUrl = $avatar['data']['url'];
         $details['avatar'] = $avatarUrl;
     }
 }
Пример #3
0
 /**
  * Links a user account with an oauth client.
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function linkOAuthUser(SocialOAuth $client, SocialUser $user, $pull = true, $push = true)
 {
     $accessToken = $client->getAccess();
     $oauth = FD::table('OAuth');
     $oauth->uid = $user->id;
     $oauth->type = SOCIAL_TYPE_USER;
     $oauth->client = $client->getType();
     $oauth->oauth_id = $client->getUser();
     $oauth->token = $accessToken->token;
     $oauth->secret = $accessToken->secret;
     $oauth->expires = $accessToken->expires;
     $oauth->pull = $pull;
     $oauth->push = $push;
     // Store the user's meta here.
     try {
         $meta = $client->getUserMeta();
     } catch (Exception $e) {
         $app = JFactory::getApplication();
         // Use dashboard here instead of login because api error calls might come from after user have successfully logged in
         $url = FRoute::dashboard(array(), false);
         $message = (object) array('message' => JText::sprintf('COM_EASYSOCIAL_OAUTH_FACEBOOK_ERROR_MESSAGE', $e->getMessage()), 'type' => SOCIAL_MSG_ERROR);
         FD::info()->set($message);
         $app->redirect($url);
         $app->close();
     }
     $params = FD::registry();
     $params->bind($meta);
     // Store the permissions
     $oauth->permissions = FD::makeJSON($client->getPermissions());
     // Set the params
     $oauth->params = $params->toString();
     // Store oauth record
     $state = $oauth->store();
     if (!$state) {
         $this->setError($oauth->getError());
         return false;
     }
     // Trigger fields to do necessary linking
     // Load profile type.
     // Get all published fields apps.
     $fieldsModel = FD::model('Fields');
     $fields = $fieldsModel->getCustomFields(array('profile_id' => $user->profile_id, 'state' => SOCIAL_STATE_PUBLISHED));
     // Prepare the arguments
     $args = array(&$meta, &$client, &$user);
     // Get the fields library
     $lib = FD::fields();
     // Get the trigger handler
     $handler = $lib->getHandler();
     // Trigger onRegisterOAuthBeforeSave
     $errors = $lib->trigger('onLinkOAuthAfterSave', SOCIAL_FIELDS_GROUP_USER, $fields, $args);
     // @TODO: Send email notification to admin that a user linked their social account with an existing account
     // @TODO: Send email notification to the account owner that they have successfully associated their social account.
     return $state;
 }