public static function login_register_user()
 {
     if ($_REQUEST['loginGoogle'] == '1') {
         $client = self::get_client();
         session_start();
         $oauth2 = new displetretsidx_Google_Oauth2Service($client);
         if (isset($_GET['code'])) {
             $client->authenticate($_GET['code']);
             $_SESSION['token'] = $client->getAccessToken();
         }
         if (isset($_SESSION['token'])) {
             $client->setAccessToken($_SESSION['token']);
         }
         if ($client->getAccessToken()) {
             $user = $oauth2->userinfo->get();
             // Filtered via PHP sanitize filters
             $email = filter_var($user['email'], FILTER_SANITIZE_EMAIL);
             global $displetretsidx_event_tracking_email;
             $displetretsidx_event_tracking_email = $email;
             $user_id = DispletRetsIdxUsersModel::get_user_id_by_email($email);
             if (!empty($user_id)) {
                 wp_set_auth_cookie($user_id, true);
                 add_action('login_head', array('DispletRetsIdxGoogleLoginController', 'include_login_event_tracking_code'), 999999999999);
             } else {
                 $user_registration_response = DispletRetsIdxLeadsController::create_new_re_search_user(array('email' => $email, 'name' => $user['name'], 'phone' => 'Google', 'url' => $_COOKIE['displet_registration_url'], 'upstream_url' => $_COOKIE['displet_upstream_url'], 'last_hash' => $_COOKIE['displetretsidx_last_viewed_hash']));
                 if (!empty($user_registration_response['success'])) {
                     add_action('login_head', array('DispletRetsIdxGoogleLoginController', 'include_registration_event_tracking_code'), 999999999999);
                 }
             }
         }
     }
 }
 public static function login_existing_facebook_user_ajax()
 {
     check_ajax_referer('displet_check_user_nonce');
     if (isset($_POST['action']) && $_POST['action'] == 'displet_user_check_request' && !empty($_POST['email']) && !empty($_POST['token'])) {
         $user_id = DispletRetsIdxUsersModel::get_user_id_by_email($_POST['email']);
         if (!empty($user_id)) {
             $json_array = wp_remote_post('https://graph.facebook.com/oauth/access_token?client_id=' . self::$_options['facebook_app_id'] . '&client_secret=' . self::$_options['facebook_app_secret'] . '&grant_type=client_credentials');
             if (!empty($json_array['body'])) {
                 $response = wp_remote_get('https://graph.facebook.com/debug_token?input_token=' . $_POST['token'] . '&' . $json_array['body']);
                 if (!empty($response['body'])) {
                     $result = json_decode($response['body']);
                     if (!empty($result->data) && !empty($result->data->is_valid) && !empty($result->data->app_id) && $result->data->app_id === self::$_options['facebook_app_id']) {
                         wp_set_auth_cookie($user_id, true);
                         echo 'User Exists and Logged In';
                     }
                 }
             }
         } else {
             echo 'There is no email account associated with this user.';
         }
         die;
     }
     echo 'We\'re sorry, there was an error processing your request. Please try again.';
     die;
 }
 private static function _save_search_registration($args)
 {
     extract(wp_parse_args($args, array('last_hash' => '', 'search_parameters' => array(), 'url' => '', 'upstream_url' => '', 'user_name' => '', 'user_email' => '', 'user_phone' => '')));
     $search_parameters = array_filter($search_parameters, array('DispletRetsIdxUtilities', 'not_empty_excluding_zero'));
     if (!empty($user_email) && !empty($search_parameters)) {
         $response = array();
         $user_id = DispletRetsIdxUsersModel::get_user_id_by_email($user_email);
         if (empty($user_id)) {
             $result = DispletRetsIdxLeadsController::create_new_re_search_user(array('email' => $user_email, 'last_hash' => $last_hash, 'name' => $user_name, 'phone' => $user_phone, 'url' => $url, 'upstream_url' => $upstream_url, 'use_cron' => false));
             if (empty($result['success'])) {
                 return $result;
             }
             $user_id = $result['user_id'];
             $response[] = 'Created User';
         }
         if (!empty($user_id)) {
             $response[] = self::_save_search(array('hash' => DispletRetsIdxResidentialsModel::get_hash_from_search_parameters($search_parameters), 'search_name' => current_time('Y/m/d g:i:s A'), 'user' => get_userdata($user_id)));
             return implode(' & ', $response);
         }
     }
 }