<?php



if (!defined('ABSPATH')) {

  exit; // Exit if accessed directly.

}



class SensFRX_Password_Reset_Failed {

  public function password_reset_failed_track($errors, $user_data) {

		$device_id = '';

		if (isset($_POST['device_id'])) {

			if (!isset($_POST['woocommerce-lost-password-nonce']) || !wp_verify_nonce(sanitize_text_field($_POST['woocommerce-lost-password-nonce']), 'woocommerce-lost-password-action')) {

				$device_id = sanitize_text_field($_POST['device_id']);

			} else {

				$device_id = null;

			}

		}

		if (empty($device_id)) {

			$device_id = null;

			$device_id_1 = null;

			$device_id_2 = null;

			$device_id_3 = null;

			$device_id_4 = null;

			$res_bot = null;

			if (isset($_COOKIE['device0'])) {   

				$device_id_1 = sanitize_text_field($_COOKIE['device0']);

			} 

			if (isset($_COOKIE['device1'])) {   

				$device_id_2 = sanitize_text_field($_COOKIE['device1']);

			}  

			if (isset($_COOKIE['device2'])) {   

				$device_id_3 = sanitize_text_field($_COOKIE['device2']);

			}  

			if (isset($_COOKIE['device3'])) {   

				$device_id_4 = sanitize_text_field($_COOKIE['device3']);

			}   

			$device_id = $device_id_1 . $device_id_2 . $device_id_3 . $device_id_4;

			if ( empty($device_id) ) {

				$device_id = null;

			} 

		}

		$options = get_option('sensfrx_options', SensFRX::default_options());

		require_once(SENSFRX_DIR . 'sensfrx-php-sdk/SensFRX/autoload.php');

		$obj = new SensFRX\SensFRX([

		'property_id' => $options['sensfrx_property_id'],

		'property_secret' => $options['sensfrx_property_secret']

		]);

		if (isset($options['sensfrx_property_id']) && isset($options['sensfrx_property_secret'])) {

			$obj = new SensFRX\SensFRX([

				'property_id' => $options['sensfrx_property_id'],

				'property_secret' => $options['sensfrx_property_secret']

			]);

			if (!$user_data) {

				$res = $obj->passwordResetAttempt('reset_password_failed', '', $device_id);

			}

		}

	}

}

