205 lines
7.0 KiB
PHP
205 lines
7.0 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
use CodeIgniter\HTTP\URI;
|
|
use App\Services\FloatLogin;
|
|
use App\Services\UserProfile;
|
|
|
|
|
|
|
|
use GuzzleHttp\Client as HTTPClient;
|
|
use Exception;
|
|
|
|
|
|
class Savvy extends BaseController
|
|
{
|
|
|
|
|
|
public function index()
|
|
{
|
|
// echo "Savvy.......";
|
|
log_message('critical', "API-WAS CALLED" );
|
|
|
|
}
|
|
|
|
public function user(){
|
|
log_message('critical', "API-WAS CALLED user" );
|
|
header("Access-Control-Allow-Origin: *");
|
|
//header("x-devicetoken : *");
|
|
//header("Authorization : Token");
|
|
header("Access-Control-Expose-Headers: Access-Control-Allow-Origin");
|
|
header("Access-Control-Allow-Headers: Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With,x-session-id, client_id, x-float-device-location-latitude, x-float-device-location-longitude, x-devicetoken");
|
|
header("Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS");
|
|
header('Content-type: application/json');
|
|
|
|
// $res = FloatLogin::floatLoginUser();
|
|
//Access-Control-Allow-Origin
|
|
|
|
if ( "OPTIONS" === $_SERVER['REQUEST_METHOD'] ) {
|
|
exit();
|
|
}
|
|
|
|
// what is the endpoint
|
|
$uri = current_url(true);
|
|
$pieces = explode("/", $uri);
|
|
$endpoint = $pieces[6];
|
|
|
|
|
|
$endpoints = array(
|
|
'getdrycleanservicelist' => array('POST'),
|
|
'createuser' => array('POST'),
|
|
'userlogin' => array('POST'),
|
|
'updateprofile' => array('POST'),
|
|
'updsprofile' => array('POST'),
|
|
'newlundrypickup' => array('POST'),
|
|
'newdrycleanpickup' => array('POST'),
|
|
'confirmlundrypickup' => array('POST'),
|
|
'savecardpayment' => array('POST'),
|
|
'getlundrylocation' => array('POST'),
|
|
'getcardpaymentlist' => array('POST'),
|
|
'getmyservicelist' => array('POST'),
|
|
'getoneserviceitem' => array('POST'),
|
|
'loadprofile' => array('POST'),
|
|
'deletecard' => array('POST')
|
|
);
|
|
|
|
|
|
if(array_key_exists( $endpoint, $endpoints)){
|
|
// echo "EXYTACT INPUT DATA HERE";
|
|
}
|
|
else{
|
|
http_response_code(404);
|
|
// tell the user product does not exist
|
|
echo json_encode(array("message" => "Product does not exist."));
|
|
}
|
|
|
|
|
|
if (!isset($endpoints[$endpoint])) {
|
|
header('HTTP/1.1 400 Bad Request');
|
|
header('Status: 400 Bad Request');
|
|
echo "{\"status\":\"Invalid endpoint url\"}";
|
|
exit();
|
|
}
|
|
|
|
$methods = $endpoints[$endpoint];
|
|
|
|
if (array_search($_SERVER['REQUEST_METHOD'], $methods)===false) {
|
|
header('HTTP/1.1 405 Method Not Allowed');
|
|
header('Status: 405 Method Not Allowed');
|
|
echo "{\"status\":\"Invalid request method\"}";
|
|
exit();
|
|
}
|
|
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
if ($endpoint == "uploadfile") {
|
|
upload_file_call();
|
|
exit();
|
|
} else {
|
|
$in = $this->flatten(json_decode(file_get_contents('php://input'), true));
|
|
}
|
|
}
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "PUT") {
|
|
parse_str(file_get_contents('php://input'), $in);
|
|
}
|
|
|
|
$in["loc"] = $_SERVER["REMOTE_ADDR"]; // get who is connecting IP
|
|
$in["pid"] = 100;
|
|
|
|
$res=[];
|
|
|
|
log_message('critical', "API-WAS CALLED user 009" );
|
|
|
|
// log_message('critical', json_encode($in) );
|
|
// log_message('critical', json_encode($_POST) );
|
|
|
|
switch ($endpoint) {
|
|
case 'getdrycleanservicelist': $in["action"] = SAVVYEXT_USER_DRYCLIST;
|
|
break;
|
|
case 'createuser': $in["action"] = SAVVYEXT_USER_CREATE;
|
|
$in["street1"] = $in["streetaddress"];
|
|
$in["zipcode"] = $in["zip"];
|
|
$in["country"] = "US";
|
|
$in["loc"] = $_SERVER["REMOTE_ADDR"];
|
|
break;
|
|
case 'userlogin': $in["action"] = SAVVYEXT_USER_LOGIN;
|
|
$res = FloatLogin::floatLoginUser();
|
|
|
|
if (!empty($res)){
|
|
$data = json_decode($res, TRUE);
|
|
if (isset($data['accessToken'])){
|
|
|
|
$res = UserProfile::floatUserProfile($data['accessToken']);
|
|
//log_message('info', 'User {id} logged into the system from {ip_address}', json_decode($ $resProfile, TRUE));
|
|
// log_message('info', $resProfile );
|
|
// $data = json_decode($resProfile, TRUE);
|
|
|
|
// $data = $resProfile; //json_decode($ $resProfile, TRUE);
|
|
// $res = $data; // array_merge($data, ['accessToken'=>$data['accessToken']] );
|
|
// $res['accessToken'] = $data['accessToken'];
|
|
}
|
|
|
|
}
|
|
break;
|
|
case 'updateprofile': $in["action"] = SAVVYEXT_USER_PROFILE;
|
|
$in["street1"] = $in["streetaddress"];
|
|
$in["zipcode"] = $in["zip"];
|
|
$in["country"] = "US";
|
|
$in["loc"] = $_SERVER["REMOTE_ADDR"];
|
|
break;
|
|
case 'updsprofile': $in["action"] = SAVVYEXT_USER_COMPLETEPROFILE;
|
|
break;
|
|
case 'getcardpaymentlist': $in["action"] = SAVVYEXT_USER_GETCCLIST;
|
|
break;
|
|
|
|
case 'newlundrypickup': $in["action"] = SAVVYEXT_USER_NEWLUNDRYPICK;
|
|
$in["service_type"] = 1;
|
|
$in["service_date"] = $in["pickupdate"] . " " . $in["pickuptime"];
|
|
break;
|
|
case 'newdrycleanpickup': $in["action"] = SAVVYEXT_USER_NEWLUNDRYPICK;
|
|
$in["service_type"] = 2;
|
|
$in["service_date"] = $in["pickupdate"] . " " . $in["pickuptime"];
|
|
break;
|
|
case 'confirmlundrypickup': $in["action"] = SAVVYEXT_USER_CONFIRMPICKUP;
|
|
break;
|
|
case 'savecardpayment': $in["action"] = SAVVYEXT_USER_SAVECARDPAYMENT;
|
|
break;
|
|
case 'getlundrylocation': $in["action"] = SAVVYEXT_USER_LUNDRYLOCATION;
|
|
$in["limit"] = 100;
|
|
break;
|
|
|
|
case 'getmyservicelist': $in["action"] = SAVVYEXT_USER_GETSERVICELIST;
|
|
break;
|
|
|
|
case 'getoneserviceitem': $in["action"] = SAVVYEXT_USER_GETSERVICEITEM;
|
|
break;
|
|
|
|
case 'loadprofile': $in["action"] = SAVVYEXT_USER_PROFILE;
|
|
break;
|
|
case 'deletecard': $in["action"] = SAVVYEXT_USER_DELETECARD;
|
|
break;
|
|
}
|
|
//echo $res;
|
|
|
|
echo json_encode($res);
|
|
exit();
|
|
|
|
}
|
|
|
|
private function flatten($data, $parentkey="") {
|
|
$result = array();
|
|
if (!is_array($data) ){
|
|
return [];
|
|
}
|
|
foreach ($data as $key=>$val) {
|
|
if (is_array($val)) {
|
|
$result = array_merge($result, flatten($val, $parentkey.$key."_"));
|
|
} else {
|
|
$result[$parentkey.$key] = $val;
|
|
}
|
|
}
|
|
return $result;
|
|
}
|
|
}
|