Esempio n. 1
0
 /**
  * Performs social login.
  * 
  * @param string $provider The name of the social network.
  */
 public function actionSocial($provider)
 {
     if (Yii::app()->hasModule('social') && Yii::app()->hasModule('registration')) {
         /* social and registration modules are loaded */
         Yii::import('application.modules.social.models.*');
         Yii::import('application.modules.social.components.*');
         try {
             $provider_params = array('redirect_uri' => 'http://' . $_SERVER['HTTP_HOST'] . Yii::app()->request->requestUri);
             $p = ProviderManager::getInstance($provider, $provider_params);
             if (isset($p)) {
                 $result = $p->isAuthorized();
                 $user = null;
                 if ($result['success']) {
                     // app authorized
                     if (!isset(Yii::app()->session['registration_user_id'])) {
                         if ($result['registration_required']) {
                             $user = UserHelper::createAccount($result['user_data']['social_email'], null, null, true, false, false);
                             $p->setSession($result['user_data']);
                             $p->storeOauthData($user->id, $result['user_data']);
                         } else {
                             $user = User::model()->findByPk($result['user_id']);
                             $identity = new SocialUserIdentity($result['user_id'], $result['user_data']);
                             $identity->authenticate();
                             $p->storeOauthData($result['user_id'], $result['user_data']);
                         }
                     } else {
                         $user = User::model()->findByPk(Yii::app()->session['registration_user_id']);
                         if (isset($user)) {
                             $p->setSession($result['user_data']);
                             $p->storeOauthData($user->id, $result['user_data']);
                         }
                     }
                     $p->pullData($result['user_data']['social_oauth_id'], $result['user_data']['social_oauth_token'], $user);
                     if (isset(Yii::app()->session['registration_user_id'])) {
                         $this->redirect(Yii::app()->createUrl('registration'));
                     } else {
                         if ($result['registration_required']) {
                             $this->redirect(Yii::app()->createUrl('registration'));
                         } else {
                             $this->redirect(Yii::app()->baseUrl);
                         }
                     }
                 } else {
                     // app not authorized
                     $this->redirect($result['url']);
                 }
             }
         } catch (Exception $ex) {
             $this->redirect(Yii::app()->createUrl('users'));
         }
     } else {
         /* modules are not loaded */
         $this->redirect(Yii::app()->createUrl('users'));
     }
 }
Esempio n. 2
0
 static function authenticate($map, $model = 'User', $provider = '')
 {
     //调用委托管理器进行身份认证
     import("ORG.RBAC.ProviderManager");
     if (empty($provider)) {
         $provider = C('USER_AUTH_PROVIDER');
     }
     $authProvider = ProviderManager::getInstance($provider);
     //使用给定的Map进行认证
     if ($authProvider->authenticate($map, $model)) {
         $authInfo = $authProvider->data;
         return $authInfo;
     } else {
         //认证失败
         return false;
     }
 }
Esempio n. 3
0
 static function authenticate($map, $model = '', $provider = '')
 {
     //调用委托管理器进行身份认证
     include dirname(__FILE__) . '/ProviderManager.class.php';
     if (empty($provider)) {
         $provider = C('USER_AUTH_PROVIDER');
     }
     if (empty($model)) {
         $model = C('USER_AUTH_MODEL');
     }
     $authProvider = ProviderManager::getInstance($provider);
     //使用给定的Map进行认证
     if ($authProvider->authenticate($map, $model)) {
         $authInfo = $authProvider->data;
         return $authInfo;
     } else {
         //认证失败
         return false;
     }
 }
Esempio n. 4
0
<?php

/*
 * PHP OEmbed provider/proxy - for details, visit
 *
 * http://code.google.com/p/php-oembed/
 *
 * Copyright(C) by Adam Nemeth. Licensed under New BSD license.
 *
 * I would love to hear every feedback on aadaam at googlesmailservice
 *
 */
require_once "config.php";
$format = $_REQUEST['format'] ? $_REQUEST['format'] : 'json';
$url = $_REQUEST['url'];
$manager = ProviderManager::getInstance();
if ($format == "xml") {
    header('Content-type: application/xml');
} else {
    if ($format == "serialized") {
    } else {
        header('Content-type: application/json');
    }
}
try {
    echo $manager->provide($url, $format);
} catch (Exception $e) {
    header("HTTP/1.0 404 Not Found");
}
 /**
  * This method can be used by other plugins. It will expand an URL to an oembed object (or null if not supported).
  * @param string $url The url to be expanded
  * @param string $maxwidth Maximum width of returned object (if service supports this). May be left empty
  * @param string $maxheight Maximum height of returned object (if service supports this). May be left empty
  * @return OEmbed or null
  */
 function expand($url, $maxwidth = null, $maxheight = null)
 {
     $obj = OEmbedDatabase::load_oembed($url);
     if (empty($obj)) {
         $config = array('audioboo_tpl' => $this->get_config('audioboo_player', 'wordpress'));
         $manager = ProviderManager::getInstance($maxwidth, $maxheight, $config);
         try {
             $obj = $manager->provide($url, "object");
             if (isset($obj)) {
                 if (!empty($obj->error)) {
                     $obj = null;
                 }
             }
             if (!isset($obj)) {
                 $obj = $this->expand_by_general_provider($url, $maxwidth, $maxheight);
                 if (isset($obj)) {
                     if (!empty($obj->error)) {
                         $obj = null;
                     }
                 }
             }
             if (isset($obj)) {
                 $obj = OEmbedDatabase::save_oembed($url, $obj);
             }
         } catch (ErrorException $e) {
             // Timeout in most cases
             //return $e;
             //print_r($e);
         }
     }
     return $obj;
 }
Esempio n. 6
0
 public static function fromDefaults()
 {
     $manager = new ProviderManager();
     $manager->add(new NoIp());
     return $manager;
 }