コード例 #1
0
ファイル: ic-functions.php プロジェクト: praveenhotha/ig
function save_token_in_session($access_token)
{
    // save token in session
    ICStore()->set(IC_TOKEN_STORAGE_KEY, $access_token);
    // update tokens in proxy instance
    ICApi()->update_tokens($access_token);
    // fetch user profile
    $response = ICApi()->auth_request('/users/me');
    // dd($response);
    // store in session
    ICStore()->set(IC_LOGGED_IN_USER_KEY, $response);
}
コード例 #2
0
ファイル: ic-hooks.php プロジェクト: praveenhotha/ig
function ic_action_handlers()
{
    if (!empty($_REQUEST['ic_action'])) {
        switch ($_REQUEST['ic_action']) {
            case 'create_community':
                // print_r($_POST);exit;
                $resp = null;
                if (!empty($_POST['community_url']) && !empty($_POST['title']) && !empty($_POST['pass']) && $_POST['pass'] === '!@adEF#$%&123' && !empty($_POST['community_id']) && !empty($_POST['oauth_consumer_key']) && !empty($_POST['oauth_consumer_secret'])) {
                    $admin_userid = 1;
                    $meta = array('public' => 1, 'community_id' => $_POST['community_id'], 'oauth_consumer_key' => $_POST['oauth_consumer_key'], 'oauth_consumer_secret' => $_POST['oauth_consumer_secret']);
                    $com_site_id = wpmu_create_blog($_POST['community_url'], "/", $_POST['title'], $admin_userid, $meta);
                    if (is_wp_error($com_site_id)) {
                        $resp = array('success' => false, 'error' => $com_site_id);
                    }
                    // copy pages from blog id 1
                    global $wpdb;
                    $table_prefix_main = $wpdb->get_blog_prefix(1);
                    $table_prefix_new = $wpdb->get_blog_prefix($com_site_id);
                    $query = "INSERT INTO {$table_prefix_new}posts \r\n\t\t\t\t\t\t\t\tSELECT p.* \r\n\t\t\t\t\t\t\t\tFROM {$table_prefix_main}posts p \r\n\t\t\t\t\t\t\t\tWHERE p.post_name IN ( 'suspended-user', 'join-error', 'error' )";
                    $wpdb->query($query);
                    //created
                    $resp = array('success' => true, 'com_site_id' => $com_site_id);
                } else {
                    $resp = array('success' => false, 'error' => new WP_Error('INVALID_PARAMS', 'Missing or Invalid Params'));
                }
                die(json_encode($resp));
                break;
            case 'verify_email':
                if (!empty($_GET['user']) && !empty($_GET['key'])) {
                    $resp = file_get_contents(IC_API_BASEURL . "/wp-json/users/{$_GET['user']}/verifyemail?key={$_GET['key']}&community=" . IC_COMMUNITY_ID);
                    if ($resp === 'true') {
                        wp_redirect("/?verified=1");
                        exit;
                    } else {
                        wp_redirect("/?verified=failed");
                        exit;
                    }
                }
                break;
            case 'link_provider':
                $user = get_logged_in_user();
                if (!empty($user) && !empty($_GET['provider']) && !empty($_GET['redirect_to'])) {
                    $code = md5($user->ID . $_GET['provider'] . "ad@#45LJWE^%\$^&*");
                    $redirect_back_url = urlencode($_GET['redirect_to']);
                    $redirect_url = IC_API_BASEURL . "?link_provider={$_GET['provider']}&userid={$user->ID}&code={$code}&redirect_to={$redirect_back_url}";
                    wp_redirect($redirect_url);
                    exit;
                }
            case 'login_gateway':
                if (!empty($_GET['community_id'])) {
                    $community_id = (int) $_GET['community_id'];
                    //fetch community config
                    $icapi = ICApi();
                    $rsp = $icapi->auth_get_request("/communities/{$community_id}/access-token");
                    if ($rsp && !is_wp_error($rsp)) {
                        $token = $rsp->tokendata;
                        $community_url = $rsp->community_url;
                        include locate_template("templates/login_gateway.php");
                        exit;
                    }
                    wp_redirect("/404");
                    exit;
                }
            case 'incoming_gateway_login':
                if (!empty($_POST['oauth_token']) && !empty($_POST['oauth_token_secret'])) {
                    $access_token = array('oauth_token' => $_POST['oauth_token'], 'oauth_token_secret' => $_POST['oauth_token_secret']);
                    save_token_in_session($access_token);
                }
                wp_redirect("/");
                exit;
                break;
            default:
                break;
        }
    }
}
コード例 #3
0
 private function done($oauth_token, $oauth_verifier)
 {
     //get the access token
     $access_token = $this->accessToken($oauth_verifier, $oauth_token);
     // save token in session
     ICStore()->set(IC_TOKEN_STORAGE_KEY, $access_token);
     // update tokens in proxy instance
     ICApi()->update_tokens($access_token);
     // fetch user profile
     $response = ICApi()->auth_request('/users/me');
     // store in session
     ICStore()->set(IC_LOGGED_IN_USER_KEY, $response);
     // check if redirect_to url is set in session, then use it
     $redirect_to = self::$store->get('redirect_to');
     if (!empty($redirect_to)) {
         // remove from session
         self::$store->set('redirect_to', '');
         wp_redirect($redirect_to);
         exit;
     }
     //redirect to home
     wp_redirect(site_url('/dashboard'));
     exit;
 }