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 send_property_showing_request()
 {
     check_ajax_referer('displet_property_showing_nonce');
     if (isset($_POST['action']) && $_POST['action'] == 'displet_property_showing_request') {
         if (!empty($_POST['name']) && !empty($_POST['email']) && (empty(self::$_options['showing_request_require_phone']) || !empty($_POST['phone']))) {
             if (is_email($_POST['email'])) {
                 $created_user = false;
                 if (is_user_logged_in()) {
                     $user_id = get_current_user_id();
                 } else {
                     $user = get_user_by('email', $_POST['email']);
                     if (empty($user)) {
                         $new_user = DispletRetsIdxLeadsController::create_new_re_search_user(array('email' => $_POST['email'], 'name' => $_POST['name'], 'phone' => $_POST['phone'], 'url' => $_POST['url'], 'upstream_url' => $_POST['upstream_url'], 'last_hash' => $_POST['last_hash'], 'listing_agent_email' => $_POST['listing_agent_email'], 'use_cron' => false));
                         if ($new_user['success']) {
                             $user_id = $new_user['user_id'];
                             $created_user = true;
                         }
                     }
                 }
                 self::_new($user_id, array('address' => $_POST['address'], 'appointment1' => $_POST['appointment1'], 'appointment2' => $_POST['appointment2'], 'city' => $_POST['city'], 'email' => $_POST['email'], 'message' => trim($_POST['message']), 'mls_number' => $_POST['mls_number'], 'name' => $_POST['name'], 'phone' => $_POST['phone'], 'state' => $_POST['state'], 'url' => $_POST['url'], 'zip' => $_POST['zip']));
                 $response = 'Sent Showing Request';
                 if ($created_user) {
                     $response .= ' and Created User';
                 }
                 echo $response;
             } else {
                 echo 'Please enter a valid email address.';
             }
         } else {
             echo 'Please complete the required fields.';
         }
         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);
         }
     }
 }
 public static function submit_registration_ajax()
 {
     check_ajax_referer('displet_register_user_nonce');
     if (isset($_POST['action']) && $_POST['action'] == 'displet_user_registration_request') {
         if (!empty($_POST['name']) && !empty($_POST['email']) && (empty(self::$_options['require_phone']) || !empty($_POST['phone'])) && (empty(self::$_options['require_working_with_realtor']) || empty(self::$_options['include_working_with_realtor']) || !empty($_POST['realtor']))) {
             if (is_email($_POST['email'])) {
                 $is_blacklisted_email = DispletRetsIdxLeadsModel::is_blacklisted_email($_POST['email']);
                 $is_blacklisted_name = DispletRetsIdxLeadsModel::is_blacklisted_name($_POST['name']);
                 if (!empty($is_blacklisted_email)) {
                     echo 'We\'re sorry, the email address provided has been prohibited.';
                 } else {
                     if (!empty($is_blacklisted_name)) {
                         echo 'We\'re sorry, the name provided has been prohibited.';
                     } else {
                         $result = DispletRetsIdxLeadsController::create_new_re_search_user(array('email' => $_POST['email'], 'name' => $_POST['name'], 'phone' => $_POST['phone'], 'realtor' => $_POST['realtor'], 'url' => $_POST['url'], 'upstream_url' => $_POST['upstream_url'], 'last_hash' => $_POST['last_hash'], 'listing_agent_email' => $_POST['listing_agent_email'], 'user_address' => $_POST['user_address'], 'user_address_time' => $_POST['user_address_time']));
                         if (!empty($result['success'])) {
                             echo 'Successful Registration';
                         } else {
                             echo $result;
                         }
                     }
                 }
             } else {
                 echo 'Please enter a valid email address.';
             }
         } else {
             echo 'Please complete the required fields.';
         }
         die;
     }
     echo 'We\'re sorry, there was an error processing your request. Please try again.';
     die;
 }
 public static function reassign_users()
 {
     check_ajax_referer('displet_reassign_users_nonce');
     if (isset($_POST['action']) && $_POST['action'] == 'displet_reassign_users_request') {
         if (!empty($_POST['displet_users'])) {
             if (!empty($_POST['displet_agent']) || !empty($_POST['displet_lender'])) {
                 foreach ($_POST['displet_users'] as $user_id) {
                     DispletRetsIdxLeadsController::reassign_user($user_id, $_POST['displet_agent'], $_POST['displet_lender']);
                 }
                 echo 'Succesful Assignation';
             } else {
                 echo 'No agent or lender has been selected.';
             }
         }
         die;
     }
 }