コード例 #1
0
function flickr_contacts_import_for_nsid($nsid, $more = array())
{
    $flickr_user = flickr_users_get_by_nsid($nsid);
    $user = users_get_by_id($flickr_user['user_id']);
    if (!$user) {
        return array('ok' => 0, 'error' => 'not a valid user');
    }
    $method = 'flickr.contacts.getList';
    $count_contacts = 0;
    $args = array('auth_token' => $flickr_user['auth_token'], 'per_page' => 100, 'page' => 1);
    $pages = null;
    while (!isset($pages) || $pages >= $args['page']) {
        $rsp = flickr_api_call($method, $args);
        if (!$rsp) {
            return array('ok' => 0, 'error' => 'The Flickr API is wigging out...');
        }
        if (!isset($pages)) {
            $pages = $rsp['rsp']['contacts']['pages'];
        }
        $contacts = $rsp['rsp']['contacts']['contact'];
        if (!is_array($contacts)) {
            return array('ok' => 0, 'error' => 'The Flickr API did not return any contacts');
        }
        foreach ($contacts as $contact) {
            $contact_nsid = $contact['nsid'];
            $contact_username = $contact['username'];
            $flickr_contact = flickr_users_get_by_nsid($contact_nsid);
            if (!$flickr_contact) {
                $password = random_string(32);
                $user_contact = users_create_user(array("username" => $contact_username, "email" => "{$contact_username}@donotsend-flickr.com", "password" => $password));
                #
                $method = 'flickr.people.getInfo';
                $args = array('user_id' => $contact_nsid);
                $rsp = flickr_api_call($method, $args);
                $path_alias = $rsp['ok'] ? $rsp['rsp']['person']['path_alias'] : '';
                #
                $flickr_contact = flickr_users_create_user(array('user_id' => $user_contact['id'], 'nsid' => $contact_nsid, 'path_alias' => $path_alias));
            }
            $rel = flickr_contacts_calculate_relationship($contact);
            # echo "{$contact_username} : {$rel} ({$contact['friend']} {$contact['family']})\n";
            $insert = array('user_id' => $user['id'], 'contact_id' => $flickr_contact['user_id'], 'rel' => $rel);
            $contact = flickr_contacts_add_contact($insert);
            $count_contacts++;
        }
        $args['page'] += 1;
    }
    return array('ok' => 1, 'count_imported' => $count_contacts);
}
コード例 #2
0
        if (!$rsp['ok']) {
            $GLOBALS['error']['foursquare_userinfo'] = 1;
            $GLOBALS['smarty']->display("page_auth_callback_foursquare_oauth.txt");
            exit;
        }
        $foursquare_id = $rsp['rsp']['user']['id'];
        $username = $rsp['rsp']['user']['firstName'];
        $email = $rsp['rsp']['user']['contact']['email'];
        if (!$email) {
            $email = "{$foursquare_id}@donotsend-foursquare.com";
        }
        if (isset($rsp['rsp']['user']['lastName'])) {
            $username .= " {$rsp['rsp']['user']['lastName']}";
        }
        $password = random_string(32);
        $user = users_create_user(array("username" => $username, "email" => $email, "password" => $password));
        if (!$user) {
            $GLOBALS['error']['dberr_user'] = 1;
            $GLOBALS['smarty']->display("page_auth_callback_foursquare_oauth.txt");
            exit;
        }
        $foursquare_user = foursquare_users_create_user(array('user_id' => $user['id'], 'oauth_token' => $oauth_token, 'foursquare_id' => $foursquare_id));
        if (!$foursquare_user) {
            $GLOBALS['error']['dberr_foursquareuser'] = 1;
            $GLOBALS['smarty']->display("page_auth_callback_foursquare_oauth.txt");
            exit;
        }
    }
}
# Okay, now finish logging the user in (setting cookies, etc.) and
# redirecting them to some specific page if necessary.
コード例 #3
0
function flickr_users_ensure_user_account($nsid, $username = '')
{
    $flickr_user = flickr_users_get_by_nsid($nsid);
    if ($flickr_user) {
        $user = users_get_by_id($flickr_user['user_id']);
        return $user;
    }
    loadlib("random");
    $password = random_string(32);
    if ($username == '') {
        $username = $nsid;
    }
    # TO DO: error handling
    $user = users_create_user(array("username" => $username, "email" => "{$username}@donotsend-flickr.com", "password" => $password));
    $flickr_user = flickr_users_create_user(array('user_id' => $user['id'], 'nsid' => $nsid));
    return $user;
}
コード例 #4
0
ファイル: signup.php プロジェクト: whosonfirst/flamework
    if ($ok && users_is_email_taken($email)) {
        $smarty->assign('email', '');
        $smarty->assign('error_email_taken', 1);
        $ok = 0;
    }
    #
    # username available?
    #
    if ($ok && users_is_username_taken($username)) {
        $smarty->assign('username', '');
        $smarty->assign('error_username_taken', 1);
        $ok = 0;
    }
    #
    # create account
    #
    if ($ok) {
        $ret = users_create_user(array('username' => $username, 'email' => $email, 'password' => $password));
        if ($ret['ok']) {
            $redir = strlen($redir) ? $redir : '/';
            login_do_login($ret['user'], $redir);
            exit;
        }
        $smarty->assign('error_failed', 1);
        $ok = 0;
    }
}
#
# output
#
$smarty->display('page_signup.txt');
コード例 #5
0
    if ($change) {
        $update = array('auth_token' => $token, 'token_perms' => $perms);
        $rsp = flickr_users_update_user($flickr_user, $update);
        if (!$rsp['ok']) {
            $GLOBALS['error']['dberr_flickruser_update'] = 1;
            $GLOBALS['smarty']->display("page_auth_callback_flickr_flickrauth.txt");
            exit;
        }
    }
} else {
    if (!$GLOBALS['cfg']['enable_feature_signup']) {
        $GLOBALS['smarty']->display("page_signup_disabled.txt");
        exit;
    } else {
        $password = random_string(32);
        $user = users_create_user(array("username" => $username, "email" => "{$username}@donotsend-flickr.com", "password" => $password));
        if (!$user) {
            $GLOBALS['error']['dberr_user'] = 1;
            $GLOBALS['smarty']->display("page_auth_callback_flickr_flickrauth.txt");
            exit;
        }
        #
        $method = 'flickr.people.getInfo';
        $args = array('user_id' => $nsid);
        $rsp = flickr_api_call($method, $args);
        $path_alias = $rsp['ok'] ? $rsp['rsp']['person']['path_alias'] : '';
        #
        $flickr_user = flickr_users_create_user(array('user_id' => $user['id'], 'nsid' => $nsid, 'path_alias' => $path_alias, 'auth_token' => $token, 'token_perms' => $perms));
        if (!$flickr_user) {
            $GLOBALS['error']['dberr_flickruser'] = 1;
            $GLOBALS['smarty']->display("page_auth_callback_flickr_flickrauth.txt");
コード例 #6
0
function flickr_contacts_import_for_nsid($nsid, $more = array())
{
    $flickr_user = flickr_users_get_by_nsid($nsid);
    $user = users_get_by_id($flickr_user['user_id']);
    if (!$user) {
        return array('ok' => 0, 'error' => 'not a valid user');
    }
    $method = 'flickr.contacts.getList';
    $all_contacts = array();
    $count_contacts = 0;
    $args = array('auth_token' => $flickr_user['auth_token'], 'per_page' => 100, 'page' => 1);
    $pages = null;
    while (!isset($pages) || $pages >= $args['page']) {
        $api_ok = 0;
        $api_error = '';
        # Can I just say this is so profoundly annoying. Why why why
        # are API calls to a federated database table failing? Anyway.
        # (20120201/straup)
        $retries = 0;
        $max_retries = 10;
        while (!$api_ok) {
            $retries += 1;
            $rsp = flickr_api_call($method, $args);
            $api_ok = $rsp['ok'];
            if (!$api_ok) {
                $api_error = "The Flickr API is wigging out: {$rsp['error']}";
            } else {
                $contacts = $rsp['rsp']['contacts']['contact'];
                if (!is_array($contacts)) {
                    $api_error = "The Flickr API did not return any contacts";
                    $api_ok = 0;
                }
            }
            echo "page: {$args['page']}/{$pages} tries: {$retries}/{$max_retries} ok: {$api_ok}\n";
            if (!$api_ok) {
                if ($retries == $max_retries) {
                    return not_okay("Unable to fetch contacts: {$api_error}");
                }
            }
        }
        if (!isset($pages)) {
            $pages = $rsp['rsp']['contacts']['pages'];
        }
        foreach ($contacts as $contact) {
            $contact_nsid = $contact['nsid'];
            $contact_username = $contact['username'];
            $flickr_contact = flickr_users_get_by_nsid($contact_nsid);
            if (!$flickr_contact) {
                $password = random_string(32);
                $user_contact = users_create_user(array("username" => $contact_username, "email" => "{$contact_username}@donotsend-flickr.com", "password" => $password));
                #
                $method = 'flickr.people.getInfo';
                $args = array('user_id' => $contact_nsid);
                $rsp = flickr_api_call($method, $args);
                $path_alias = $rsp['ok'] ? $rsp['rsp']['person']['path_alias'] : '';
                #
                $flickr_contact = flickr_users_create_user(array('user_id' => $user_contact['id'], 'nsid' => $contact_nsid, 'path_alias' => $path_alias));
            }
            $rel = flickr_contacts_calculate_relationship($contact);
            # echo "{$contact_username} : {$rel} ({$contact['friend']} {$contact['family']})\n";
            $insert = array('user_id' => $user['id'], 'contact_id' => $flickr_contact['user_id'], 'rel' => $rel);
            $all_contacts[] = $insert;
        }
        $args['page'] += 1;
    }
    if (isset($more['purge_existing_contacts'])) {
        $rsp = flickr_contacts_purge_contacts($user);
        if (!$rsp['ok']) {
            return not_okay("failed to purge existing contacts: {$rsp['error']}");
        }
    }
    # echo "import " . count($all_contacts) . " contacts\n";
    foreach ($all_contacts as $insert) {
        if (flickr_contacts_add_contact($insert)) {
            $count_contacts++;
        }
    }
    return array('ok' => 1, 'count_imported' => $count_contacts);
}