HEX
Server: Apache/2.4.34 (Red Hat) OpenSSL/1.0.2k-fips
System: Linux WORDPRESS 3.10.0-1160.118.1.el7.x86_64 #1 SMP Thu Apr 4 03:33:23 EDT 2024 x86_64
User: digital (1020)
PHP: 7.2.24
Disabled: NONE
Upload Files
File: /datos/www/expodubai/wp-content/plugins/themeftc/includes/auth.php
<?php 
/**
 * Social network authentication
 */

class Ftc_Social_Author {
    
    public $current_url;
    public $available_networks = array( 'facebook', 'vkontakte', 'google' );

	function __construct() {
        $this->current_url = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . "{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
    	add_action('init', array( $this, 'auth' ), 20);
    	add_action('init', array( $this, 'process_auth_callback' ), 30);
	}

    function auth() {

        global $smof_data;
        
        if( empty( $_GET['login'] ) && empty( $_GET['code'] ) ) {
            return;
        }

        $network = ( empty( $_GET['login'] ) ) ? $this->get_current_callback_network() : sanitize_key( $_GET['login'] );

        if( ! in_array( $network, $this->available_networks) ) return;

        $account_url    = $this->get_account_url();
        $security_salt  = apply_filters('ftc_opauth_salt', 'k9QVRc7R3woOOVyJgOFBv2Rp9bxQsGtRbaOraP7ePXuyzh0GkrNckKjI4MV1KOy');

        $callback_param = 'int_callback';
        $strategy = array();
        switch ( $network ) {
            case 'google':
                $app_id         = $smof_data['ftc_google_app_id'];
                $app_secret     = $smof_data['ftc_google_app_secret'];

                if( empty( $app_secret ) || empty( $app_id ) ) return;

                $strategy       = array(
                    'Google' => array(
                        'client_id' => $app_id,
                        'client_secret' => $app_secret,
                        #'scope' => 'email'
                    ),
                );

                $callback_param = 'oauth2callback';

            break;

            case 'vkontakte':
                $app_id         = $smof_data['ftc_vk_app_id'];
                $app_secret     = $smof_data['ftc_vk_app_secret'];

                if( empty( $app_secret ) || empty( $app_id ) ) return;

                $strategy       = array(
                    'VKontakte' => array(
                        'app_id' => $app_id,
                        'app_secret' => $app_secret,
                        'scope' => 'email'
                    ),
                );
            break;

            default:
                $app_id         = $smof_data['ftc_facebook_app_id'];
                $app_secret     = $smof_data['ftc_facebook_app_secret'];

                if( empty( $app_secret ) || empty( $app_id ) ) return;

                $strategy       = array(
                    'Facebook' => array(
                        'app_id' => $app_id,
                        'app_secret' => $app_secret,
                        'scope' => 'email'
                    ),
                );
            break;
        }

        $config = array(
            'security_salt'         => $security_salt,
            'host'                  => $account_url,
            'path'                  => '/',
            'callback_url'          => $account_url,
            'callback_transport'    => 'get',
            'strategy_dir'          => plugin_dir_path( __DIR__ ) . '/vendor/opauth/',
            'Strategy'              => $strategy
        );


        if( empty( $_GET['code'] ) ) {
            $config['request_uri'] = '/' . $network;
        } else {
            $config['request_uri'] = '/' . $network . '/' . $callback_param . '?code=' . $_GET['code'];
        }
     
        new Opauth( $config );
    }

    function process_auth_callback() {
        if( empty( $_GET['opauth'] ) || is_user_logged_in() ) return;

        $opauth = unserialize(base64_decode($_GET['opauth']));

        switch ( $opauth['auth']['provider'] ) {
            case 'Facebook':
                if( empty( $opauth['auth']['info'] ) ) {
                    wc_add_notice( __( 'Can\'t login with Facebook. Please, try again later.', 'themeftc' ), 'error' );
                    return;
                }

                elseif( empty( $opauth['auth']['info']['email'] ) ) {
                    wc_add_notice( __( 'Facebook doesn\'t provide your email. Try to register manually.', 'themeftc' ), 'error' );
                    return;
                } else {
                    $email = $opauth['auth']['info']['email'];
                    $this->register_or_login( $email );
                }
   
            break;
            case 'Google':

                if( empty( $opauth['auth']['info'] ) ) {
                    wc_add_notice( __( 'Can\'t login with Google. Please, try again later.', 'themeftc' ), 'error' );
                    return;
                }

                elseif( empty( $opauth['auth']['info']['email'] ) ) {
                    wc_add_notice( __( 'Google doesn\'t provide your email. Try to register manually.', 'themeftc' ), 'error' );
                    return;
                } else {
                    $email = $opauth['auth']['info']['email'];
                    $this->register_or_login( $email );
                }
            break;
            case 'VKontakte':

                if( empty( $opauth['auth']['info'] ) ) {
                    wc_add_notice( __( 'Can\'t login with VKontakte. Please, try again later.', 'themeftc' ), 'error' );
                    return;
                }

                elseif( empty( $opauth['auth']['info']['email'] ) ) {
                    wc_add_notice( __( 'VK doesn\'t provide your email. Try to register manually.', 'themeftc' ), 'error' );
                    return;
                } else {
                    $email = $opauth['auth']['info']['email'];
                    $this->register_or_login( $email );
                }

            break;
            
            default:
            break;
        }
    }

    function register_or_login( $email ) {

        add_filter('pre_option_woocommerce_registration_generate_username', array( $this, 'return_yes' ), 10);

        $password = wp_generate_password();
        $customer = wc_create_new_customer( $email, '', $password);

        $user = get_user_by('email', $email);

        if( is_wp_error( $customer ) ) {
            if( isset( $customer->errors['registration-error-email-exists'] ) ) {
                wc_set_customer_auth_cookie( $user->ID );
            }
        } else {
            wc_set_customer_auth_cookie( $customer );
        }

        wc_add_notice( sprintf( __( 'You are now logged in as <strong>%s</strong>', 'woocommerce' ), 'error') );

        remove_filter('pre_option_woocommerce_registration_generate_username', array( $this, 'return_yes' ), 10);
    }

    function get_current_callback_network() {
        $account_url = $this->get_account_url();

        foreach ($this->available_networks as $network) {
            if( strstr( $this->current_url, trailingslashit( $account_url ) . $network ) ) {
                return $network;
            }
        }

        return false;
    }

    function get_account_url() {
        return untrailingslashit( wc_get_page_permalink('myaccount') );
    }

    function return_yes() {
        return 'yes';
    }
}
new Ftc_Social_Author();