File: /var/www/grapossconnect/center-admin/api/agent_info.php
<?php
header("Access-Control-Allow-Origin: *");
header('Content-Type: application/json');
include '../../sample-wp/wp-config.php';
//decode function
function decodeReq($value)
{
$str = substr($value, 12);
$str1 = substr($str, 0, -11);
$decode = base64_decode($str1);
return $decode;
}
$json = file_get_contents('php://input');
$data = json_decode($json);
if (isset($data)) {
$type = $data->type;
$agent_id = decodeReq($data->x);
$date = date('Y-m-d H:i:s');
if ($type == 'chng-pwd') {
$currnt = md5($data->c);
$new = md5($data->n);
$getAgentPwd = $wpdb->get_row("SELECT password from grp_agents where agent_id='$agent_id'");
if ($currnt != $getAgentPwd->password) {
$array = array("status" => 0, "resp" => "Error:Current password is wrong");
} else if ($getAgentPwd->password == $new) {
$array = array("status" => 0, "resp" => "Error:New password should not equal to old password");
} else {
$updatePwd = "UPDATE grp_agents set password='$new' where agent_id='$agent_id'";
if ($wpdb->query($updatePwd)) {
session_start();
unset($_SESSION["AGENT_ID"]);
session_unset();
session_destroy();
$array = array("status" => 1, "resp" => "Password update successfully");
} else {
$array = array("status" => 0, "resp" => "Error:Password not updated");
}
}
} else if($type == 'chng-pin') {
$newPin = $data->c;
$getPin = $wpdb->get_row("SELECT wallet_pin FROM grp_agents_wallet where agent_id='$agent_id'");
if($getPin->wallet_pin == $newPin) {
$array = array("status" => 0, "resp" => "Error:New pin should not equal to Old pin");
} else {
$updatePin = "UPDATE grp_agents_wallet set wallet_pin='$newPin',last_pin_date='$date' where agent_id='$agent_id'";
if ($wpdb->query($updatePin)) {
$array = array("status" => 1, "resp" => "Pin update successfully");
} else {
$array = array("status" => 0, "resp" => "Error:Pin not updated");
}
}
}
echo json_encode($array);
}