Example #1
0
/**
* Authenticate a user within wordpress
*
* Ref: http://codex.wordpress.org/Function_Reference/wp_set_auth_cookie
* Ref: http://codex.wordpress.org/Function_Reference/wp_safe_redirect
*/
function wsl_process_login_authenticate_wp_user($user_id, $provider, $redirect_to, $adapter, $hybridauth_user_profile, $wp_user)
{
    // HOOKABLE:
    do_action("wsl_process_login_authenticate_wp_user_start", $user_id, $provider, $redirect_to, $adapter, $hybridauth_user_profile, $wp_user);
    // update some fields in usermeta for the current user
    update_user_meta($user_id, 'wsl_current_provider', $provider);
    //update_user_meta( $user_id, 'wsl_'.$provider , $provider );
    //var_dump($hybridauth_user_profile);
    //die();
    //$existing_user = wsl_get_stored_hybridauth_user_profiles_by_user_id($user_id);
    //var_dump($existing_user); die();
    $disciplines = array("dota" => 1, "cs" => 2);
    $regions = array("CES" => 1, "CN" => 2, "EU" => 3);
    $method = "";
    if ($provider == "Steam") {
        $user_current_steam = get_user_meta($user_id, 'user_steam');
        $region = "CES";
        $discipline_name = "dota";
        $discipline_data = array();
        if ($user_current_steam[$discipline_name]) {
            $user_current_steam = json_decode($user_current_steam);
            $discipline_data = $user_current_steam[$discipline_name];
            $method = "PUT";
        } else {
            $method = "POST";
        }
        if ($discipline_name and $region) {
            if ($hybridauth_user_profile->identifier) {
                $discipline_data[$discipline_name]["steam_id"] = $hybridauth_user_profile->identifier;
            }
            if ($hybridauth_user_profile->displayName) {
                $discipline_data[$discipline_name]["steam_displayName"] = $hybridauth_user_profile->displayName;
            }
            if ($hybridauth_user_profile->photoURL) {
                $discipline_data[$discipline_name]["steam_avatar"] = $hybridauth_user_profile->photoURL;
            }
            $discipline_data[$discipline_name]["region"] = $region;
        }
        CallSLTVAPI($method, "http://api.sltv.pro/api/v1/user_disciplines", array('user_id' => $user_id, 'discipline_id' => $disciplines[$discipline_name], 'region_id' => $regions[$region], 'game_unique_id' => $discipline_data["steam_id"]));
        $discipline_data = json_encode($discipline_data);
        update_user_meta($user_id, 'user_steam', $discipline_data);
    }
    if ($hybridauth_user_profile->photoURL) {
        update_user_meta($user_id, 'wsl_current_user_image', $hybridauth_user_profile->photoURL);
    }
    // Bouncer::User Moderation
    // > When Bouncer::User Moderation is enabled, WSL will check for the current user role. If equal to 'pending', then Bouncer will do the following :
    // 	1. Halt the authentication process,
    // 	2. Skip setting the authentication cookies for the user,
    // 	3. Reset the Redirect URL to the appropriate Theme My Login page.
    $wsl_settings_bouncer_new_users_moderation_level = get_option('wsl_settings_bouncer_new_users_moderation_level');
    // current user role
    $role = current($wp_user->roles);
    // if role eq 'pending', we halt the authentication and we redirect the user to the appropriate url (pending=activation or pending=approval)
    if ($role == 'pending') {
        // E-mail Confirmation
        if ($wsl_settings_bouncer_new_users_moderation_level == 101) {
            $redirect_to = site_url('wp-login.php', 'login_post') . (strpos(site_url('wp-login.php', 'login_post'), '?') ? '&' : '?') . "pending=activation";
            // send a new e-mail/activation notification - if TML not enabled, we ensure WSL to keep it quiet
            @Theme_My_Login_User_Moderation::new_user_activation_notification($user_id);
        } elseif ($wsl_settings_bouncer_new_users_moderation_level == 102) {
            $redirect_to = site_url('wp-login.php', 'login_post') . (strpos(site_url('wp-login.php', 'login_post'), '?') ? '&' : '?') . "pending=approval";
        }
    } else {
        // HOOKABLE: This action runs just before logging the user in (before creating a WP cookie)
        do_action("wsl_hook_process_login_before_wp_set_auth_cookie", $user_id, $provider, $hybridauth_user_profile);
        // DEPRECIATED: as of 2.2.3
        // do_action( 'wsl_hook_process_login_before_set_auth_cookie', $user_id, $provider, $hybridauth_user_profile );
        // Set WP auth cookie
        wp_set_auth_cookie($user_id, true);
        // let keep it std
        do_action('wp_login', $wp_user->user_login, $wp_user);
    }
    // HOOKABLE: This action runs just before redirecting the user back to $redirect_to
    // > Note: If you have enabled User Moderation, then the user is NOT NECESSARILY CONNECTED
    // > within wordpress at this point (in case the user $role == 'pending').
    // > To be sure the user is connected, use wsl_hook_process_login_before_wp_set_auth_cookie instead.
    do_action("wsl_hook_process_login_before_wp_safe_redirect", $user_id, $provider, $hybridauth_user_profile, $redirect_to);
    // DEPRECIATED: as of 2.2.3
    // do_action( 'wsl_hook_process_login_before_set_auth_cookie', $user_id, $provider, $hybridauth_user_profile );
    do_action('wsl_clear_user_php_session');
    // Display WSL debugging instead of redirecting the user
    // > this will give a complete report on what wsl did : database queries and fired hooks
    // wsl_display_dev_mode_debugging_area(); die(); // ! keep this line commented unless you know what you are doing :)
    // That's it. We done.
    wp_safe_redirect($redirect_to);
    // for good measures
    die;
}
Example #2
0
 function sltv_save_user($user_id)
 {
     $user = get_user_by('id', $user_id);
     $avatar_url = get_avatar_url($user_id);
     $type = pathinfo($avatar_url, PATHINFO_EXTENSION);
     $data = file_get_contents($avatar_url);
     $base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
     var_dump($base64);
     echo "<hr>";
     if ($user) {
         var_dump(CallSLTVAPI("POST", "http://api.sltv.pro/api/v1/users/" . $user_id, array('email' => $user->get("user_email"), 'nick' => $user->get("user_nicename"), 'logo' => $base64)));
         die;
     }
 }