/**
* Entry point to the authentication process
*
* This function runs after WordPress has finished loading but before any headers are sent.
* This function will analyse the current URL parameters and start the login process whenever an
* WSL action is found: $_REQUEST['action'] eq wordpress_social_*
*
* Example of valid origin url:
*    wp-login.php
*       ?action=wordpress_social_authenticate                        // current step
*       &mode=login                                                  // auth mode
*       &provider=Twitter                                            // selected provider
*       &redirect_to=http%3A%2F%2Fexample.com%2Fwordpress%2F%3Fp%3D1 // where the user come from
*
* Ref: http://codex.wordpress.org/Plugin_API/Action_Reference/init
*/
function wsl_process_login()
{
    // > check for wsl actions
    $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
    if (!in_array($action, array("wordpress_social_authenticate", "wordpress_social_profile_completion", "wordpress_social_account_linking", "wordpress_social_authenticated"))) {
        return false;
    }
    // authentication mode
    $auth_mode = wsl_process_login_get_auth_mode();
    // start loggin the auth process, if debug mode is enabled
    wsl_watchdog_init();
    // halt, if mode login and user already logged in
    if ('login' == $auth_mode && is_user_logged_in()) {
        global $current_user;
        get_currentuserinfo();
        return wsl_process_login_render_notice_page(sprintf(_wsl__("You are already logged in as %s. Do you want to <a href='%s'>log out</a>?", 'wordpress-social-login'), $current_user->display_name, wp_logout_url(home_url())));
    }
    // halt, if mode link and user not logged in
    if ('link' == $auth_mode && !is_user_logged_in()) {
        return wsl_process_login_render_notice_page(sprintf(_wsl__("You have to be logged in to be able to link your existing account. Do you want to <a href='%s'>login</a>?", 'wordpress-social-login'), wp_login_url(home_url())));
    }
    // halt, if mode test and not admin
    if ('test' == $auth_mode && !current_user_can('manage_options')) {
        return wsl_process_login_render_notice_page(_wsl__('You do not have sufficient permissions to access this page.', 'wordpress-social-login'));
    }
    // Bouncer :: Allow authentication?
    if (get_option('wsl_settings_bouncer_authentication_enabled') == 2) {
        return wsl_process_login_render_notice_page(_wsl__("Authentication through social networks is currently disabled.", 'wordpress-social-login'));
    }
    add_action('wsl_clear_user_php_session', 'wsl_process_login_clear_user_php_session');
    // HOOKABLE:
    do_action("wsl_process_login_start");
    // if action=wordpress_social_authenticate
    // > start the first part of authentication (redirect the user to the selected provider)
    if ($action == "wordpress_social_authenticate") {
        return wsl_process_login_begin();
    }
    // if action=wordpress_social_authenticated or action=wordpress_social_profile_completion
    // > finish the authentication process (create new user if doesn't exist in database, then log him in within wordpress)
    wsl_process_login_end();
}
Пример #2
0
/**
* Entry point to the authentication process
*
* This function runs after WordPress has finished loading but before any headers are sent.
* This function will analyse the current URL parameters and start the login process whenever an
* WSL action is found: $_REQUEST['action'] eq wordpress_social_*
*
* Example of valid origin url:
*    wp-login.php
*       ?action=wordpress_social_authenticate                        // current step
*       &mode=login                                                  // auth mode
*       &provider=Twitter                                            // selected provider
*       &redirect_to=http%3A%2F%2Fexample.com%2Fwordpress%2F%3Fp%3D1 // where the user come from
*
* Ref: http://codex.wordpress.org/Plugin_API/Action_Reference/init
*/
function wsl_process_login()
{
    // > check for wsl actions
    $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
    if (!in_array($action, array("wordpress_social_authenticate", "wordpress_social_profile_completion", "wordpress_social_account_linking", "wordpress_social_authenticated"))) {
        return false;
    }
    // authentication mode
    $auth_mode = wsl_process_login_get_auth_mode();
    // start loggin the auth process, if debug mode is enabled
    wsl_watchdog_init();
    // halt, if mode login and user already logged in
    if ('login' == $auth_mode && is_user_logged_in()) {
        global $current_user;
        get_currentuserinfo();
        return wsl_process_login_render_notice_page(sprintf(_wsl__("თქვენ ავტორიზებული ხართ როგორც %s. გსურთ <a href='%s'>გასვლა</a>?", 'wordpress-social-login'), $current_user->display_name, wp_logout_url(home_url())));
    }
    // halt, if mode link and user not logged in
    if ('link' == $auth_mode && !is_user_logged_in()) {
        return wsl_process_login_render_notice_page(sprintf(_wsl__("უნდა იყოთ ავტორიზებული იმისათვის რომ დაუკავშირდეთ თვენს მომხმარებელს. გსურთ <a href='%s'>შესვლა</a>?", 'wordpress-social-login'), wp_login_url(home_url())));
    }
    // halt, if mode test and not admin
    if ('test' == $auth_mode && !current_user_can('manage_options')) {
        return wsl_process_login_render_notice_page(_wsl__('თქვენ არ გაქვთ გარკვეული პრივილეგიები რომ ეწვიოთ ამ გვერდს.', 'wordpress-social-login'));
    }
    // Bouncer :: Allow authentication?
    if (get_option('wsl_settings_bouncer_authentication_enabled') == 2) {
        return wsl_process_login_render_notice_page(_wsl__("ავტორიზაცია სოციალური ქსელებით ამჟამად გამორთულია.", 'wordpress-social-login'));
    }
    add_action('wsl_clear_user_php_session', 'wsl_process_login_clear_user_php_session');
    // HOOKABLE:
    do_action("wsl_process_login_start");
    // if action=wordpress_social_authenticate
    // > start the first part of authentication (redirect the user to the selected provider)
    if ($action == "wordpress_social_authenticate") {
        return wsl_process_login_begin();
    }
    // if action=wordpress_social_authenticated or action=wordpress_social_profile_completion
    // > finish the authentication process (create new user if doesn't exist in database, then log him in within wordpress)
    wsl_process_login_end();
}