コード例 #1
0
ファイル: rules.php プロジェクト: undomick/cgru
function jsf_initialize($i_arg, &$o_out)
{
    global $UserID, $Groups, $HT_AccessFileName, $HT_GroupsFileName;
    $configs = array();
    readConfig('config_default.json', $configs);
    $o_out['config'] = $configs;
    if ($UserID != null) {
        if (false == is_file($HT_AccessFileName) && is_file('htaccess_example')) {
            if (copy('htaccess_example', $HT_AccessFileName)) {
                error_log('HT access file copied.');
            } else {
                error_log('Unable to copy htaccess file.');
            }
        }
        if (false == is_file($HT_GroupsFileName)) {
            $Groups = array();
            $Groups['admins'] = array($UserID);
            jsf_writegroups($Groups, $o_out);
            if (array_key_exists('error', $o_out)) {
                return;
            }
            error_log('HT Groups file created with "' . $UserID . '" in "admins".');
        }
    }
    processUser($o_out);
    if (array_key_exists('error', $o_out)) {
        return;
    }
    $out = array();
    getallusers($out);
    if (array_key_exists('error', $out)) {
        $o_out['error'] = $out['error'];
        return;
    }
    $o_out['users'] = array();
    foreach ($out['users'] as $obj) {
        $user = array();
        $user['id'] = $obj['id'];
        // We do not send all users props to each user.
        $props = array('title', 'role', 'states', 'disabled', 'signature');
        foreach ($props as $prop) {
            if (isset($obj[$prop])) {
                $user[$prop] = $obj[$prop];
            }
        }
        if (isset($obj['avatar']) && strlen($obj['avatar'])) {
            $user['avatar'] = $obj['avatar'];
        } else {
            if (isset($obj['email']) && strlen($obj['email'])) {
                $user['avatar'] = 'http://www.gravatar.com/avatar/' . md5(strtolower(trim($obj['email'])));
            }
        }
        $o_out['users'][$obj['id']] = $user;
    }
    if (isAdmin($out)) {
        $o_out['admin'] = true;
    }
}
コード例 #2
0
ファイル: fb2.php プロジェクト: rjha/sc
    $params = null;
    parse_str($response, $params);
    if (!is_array($params) && !array_key_exists("access_token", $params)) {
        $message = "Could not retrieve access_token from Facebook";
        Logger::getInstance()->error($message);
        raiseUIError();
    }
    $graph_url = "https://graph.facebook.com/me?access_token=" . $params["access_token"];
    $user = json_decode(file_get_contents($graph_url));
    if (!property_exists($user, 'id')) {
        $message = "No facebook_id in graph API response";
        Logger::getInstance()->error($message);
        raiseUIError();
    }
    $expires = isset($params["expires"]) ? $params["expires"] : 3600;
    processUser($user, $params["access_token"], $expires);
} else {
    $message = "CSRF token returned by Facebook is different from 3mik session token";
    Logger::getInstance()->error($message);
    raiseUIError();
}
/**
 * 
 * @param access_token - access token returned by facebook for offline use
 * @param expires - time in seconds till the access_token expiry  
 * 
 * 
 */
function processUser($user, $access_token, $expires)
{
    // exisitng record ? find on facebook_id
コード例 #3
0
ファイル: twitter.php プロジェクト: rjha/sc
    $message = "Twitter login :: oauth verifier is missing";
    Logger::getInstance()->error($message);
    raiseUIError();
}
$appId = Config::getInstance()->get_value("twitter.app.id");
$appSecret = Config::getInstance()->get_value("twitter.app.secret");
$connection = new TwitterOAuth($appId, $appSecret, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
/* get access token from twitter and save in session */
$access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']);
$_SESSION['access_token'] = $access_token;
/* Remove no longer needed request tokens */
unset($_SESSION['oauth_token']);
unset($_SESSION['oauth_token_secret']);
/* continue If HTTP response is 200 */
if (200 == $connection->http_code) {
    processUser($connection);
} else {
    clearSession();
    $message = "Could not retrieve Twitter access_token";
    Logger::getInstance()->error($message);
    raiseUIError();
}
function processUser($connection)
{
    $user_info = $connection->get('account/verify_credentials');
    if (isset($user_info->error)) {
        $message = "Error retrieving twitter user information";
        Logger::getInstance()->error($message);
        raiseUIError();
    } else {
        // get screenName, profile Pic
コード例 #4
0
ファイル: google2.php プロジェクト: rjha/sc
    //json fine but access_token is missing
    if (!property_exists($jsObject, "access_token")) {
        $message = "Could not retrieve access token from Google";
        Logger::getInstance()->error($message);
        raiseUIError();
    }
    //Now call the userinfo  endpoint using access tokens
    $url = "https://www.googleapis.com/oauth2/v1/userinfo?access_token=" . $jsObject->access_token;
    $response = file_get_contents($url);
    $user = json_decode($response);
    if (!property_exists($user, "id")) {
        $message = "No google_id in google userinfo endpoint response";
        Logger::getInstance()->error($message);
        raiseUIError();
    }
    processUser($user);
} else {
    $message = "CSRF token returned by google does not match the one stored in 3mik session";
    Logger::getInstance()->error($message);
    raiseUIError();
}
function processUser($user)
{
    $id = $user->id;
    if (empty($id)) {
        trigger_error("Could not retrieve google id : please try again.", E_USER_ERROR);
    }
    //rest of the properties may be missing
    $email = property_exists($user, 'email') ? $user->email : '';
    $name = property_exists($user, 'name') ? $user->name : '';
    $firstName = property_exists($user, 'given_name') ? $user->given_name : '';