389 lines
13 KiB
PHP
389 lines
13 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(){
|
|
|
|
/*encryption:
|
|
{
|
|
algorithm = "aes-256-ctr";
|
|
key = "1234567890abcdef1234567890abcdef";
|
|
iv = "1234567890abcdef";
|
|
};
|
|
|
|
*/
|
|
$inx=[];
|
|
$encryptionAlg = "aes-256-ctr"; // $savvyext->cfgReadChar('encryption.algorithm');
|
|
$encryptionKey = "1234567890abcdef1234567890abcdef"; // $savvyext->cfgReadChar('encryption.key');
|
|
$encryptionIV = "1234567890abcdef"; // $savvyext->cfgReadChar('encryption.iv');
|
|
|
|
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(
|
|
'createuser' => array('POST'),
|
|
'userlogin' => array('POST'),
|
|
'tracklocation' => array('POST'),
|
|
'savecardpayment' => array('POST'),
|
|
'getcardpaymentlist' => array('POST'),
|
|
'managepaymentlist' => array('POST'),
|
|
'loadprofile' => array('POST'),
|
|
'updateprofile' => array('POST'),
|
|
'verifysession' => array('POST'),
|
|
"refreshsession" => array('POST'),
|
|
'linkemail' => array('POST'),
|
|
'listlinkedemail' => array('POST'),
|
|
'refreshlinkemail' => array('POST'),
|
|
'usertransportlist' => array('POST'),
|
|
'usertransportprofile' => array('POST'),
|
|
'getdashcarddata' => array('POST'),
|
|
'loadsavedcards' => array('POST'),
|
|
'savedashcard' => array('POST'),
|
|
'saveuserbudget' => array('POST'),
|
|
'resetpass' => array('POST'),
|
|
'settingsarray' => array('POST'),
|
|
'loadsubsription' => array('POST'),
|
|
'subscriptionstatus' => array('POST'),
|
|
'getapplist' => array('POST'),
|
|
'getslidecarddata' => array('POST'),
|
|
'subscribedcarddata' => array('POST'),
|
|
'subscribecard' => array('POST'),
|
|
"savesurvey" => array('POST'),
|
|
"pointsdetail" => array('POST'),
|
|
"loadredeemabale" => array('POST'),
|
|
"redeempoints" => array('POST'),
|
|
"managefeature" => array('POST'),
|
|
"carpool" => array('POST'),
|
|
'logout' => array('POST'),
|
|
"carpoolstatus" => array('POST'),
|
|
"getsavedtrips" => array('POST'),
|
|
"savedtrip" => array('POST'),
|
|
"removesavedtrip" => array('POST'),
|
|
"trackcardclick" => array('POST'),
|
|
"membersettings" => array('POST'),
|
|
"persnoality" => 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));
|
|
$raw_json = file_get_contents("php://input");
|
|
$raw_array = json_decode($raw_json, true);
|
|
if ($endpoint == "createuser") {
|
|
$inx = $raw_array;
|
|
} else {
|
|
$inx = $this->flatten($raw_array);
|
|
$this->logArray($inx);
|
|
}
|
|
}
|
|
}
|
|
|
|
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=>".$endpoint );
|
|
|
|
// log_message('critical', json_encode($in) );
|
|
// log_message('critical', json_encode($_POST) );
|
|
// $inx = $_POST;
|
|
$this->logArray($inx);
|
|
// Decrypt the input
|
|
if (isset($inx['encrypted_payload'])) {
|
|
log_message('critical', "API-WAS DECRYPT STARTED=>".$endpoint );
|
|
$payload = openssl_decrypt(hex2bin($inx['encrypted_payload']), $encryptionAlg, $encryptionKey, OPENSSL_RAW_DATA, $encryptionIV);
|
|
log_message('critical', "API-WAS DECRYPT END=>".$endpoint );
|
|
|
|
unset($inx['encrypted_payload']);
|
|
$inx = array_merge($in, json_decode($payload, true));
|
|
}
|
|
|
|
|
|
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;
|
|
log_message('critical', "API-WAS CALLED user 10-009=>".$endpoint );
|
|
|
|
//{"username":"ses66181@gmail.com","password":"12345678","sessionid":"DUMMYSESSION","loc":"172.24.0.1","pid":100}
|
|
if ($inx['username'] == 'ses66181@gmail.com'){
|
|
$res= $this->dummy_data();
|
|
}
|
|
else{
|
|
$resLogin = FloatLogin::floatLoginUser($inx['username'], $inx['password']);
|
|
log_message('critical', "Login Returned=>".$endpoint );
|
|
$this->logArray($resLogin);
|
|
$resLoginArray = json_decode($resLogin, true);
|
|
$this->logArray($resLoginArray);
|
|
log_message('critical', "Ready for Profile=>".$resLoginArray['accessToken'] );
|
|
if (!empty($resLoginArray) && is_array($resLoginArray)){
|
|
if (isset($resLoginArray['accessToken'])){
|
|
$resProfile = UserProfile::floatUserProfile($resLoginArray['accessToken']);
|
|
$this->logArray($resProfile);
|
|
$res = json_decode($resProfile, true);
|
|
$this->logArray($res);
|
|
}
|
|
}
|
|
else{
|
|
log_message('critical', "Login Failed for User=>".$inx['username'] );
|
|
$res["internal_return"] = "0";
|
|
}
|
|
}
|
|
|
|
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;
|
|
|
|
if (!empty($inx) && is_array($inx)){
|
|
if (isset($inx['sessionid'])){
|
|
$inx['accessToken'] = $inx['sessionid'];
|
|
$resProfile = UserProfile::floatUserProfile($inx['accessToken']);
|
|
$this->logArray($resProfile);
|
|
$res = json_decode($resProfile, true);
|
|
$this->logArray($res);
|
|
}
|
|
}
|
|
break;
|
|
case 'deletecard': $in["action"] = SAVVYEXT_USER_DELETECARD;
|
|
break;
|
|
}
|
|
//echo $res;
|
|
|
|
// $result = ['payload'=>$res]; only when encrypted
|
|
|
|
$result = $res; // when not encryped;
|
|
$this->logArray($result);
|
|
|
|
|
|
echo json_encode($result);
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
private function logArray($in){
|
|
if (!is_array($in)){
|
|
log_message('critical', "NOT ARRAY => $in \n");
|
|
return;
|
|
}
|
|
foreach($in as $key => $value){
|
|
$vl='';
|
|
if (is_array($value)){
|
|
foreach($value as $kk => $vv){
|
|
$vl .= "$kk => $vv \n";
|
|
}
|
|
}
|
|
else{
|
|
$vl=$value;
|
|
}
|
|
|
|
log_message('critical', "$key=>".$vl);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public function oauth2(){
|
|
log_message('critical', "API-WAS CALLED oauth2" );
|
|
return [];
|
|
}
|
|
|
|
public function banklogin(){
|
|
log_message('critical', "API-WAS CALLED banklogin" );
|
|
return [];
|
|
}
|
|
|
|
public function booking(){
|
|
log_message('critical', "API-WAS CALLED booking" );
|
|
|
|
return [];
|
|
}
|
|
|
|
|
|
public function advice(){
|
|
log_message('critical', "API-WAS CALLED advice" );
|
|
|
|
return [];
|
|
}
|
|
|
|
public function trips(){
|
|
log_message('critical', "API-WAS CALLED trips" );
|
|
|
|
return [];
|
|
}
|
|
|
|
public function blog(){
|
|
log_message('critical', "API-WAS CALLED blog" );
|
|
return [];
|
|
}
|
|
|
|
|
|
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;
|
|
}
|
|
|
|
private function dummy_data(){
|
|
$out=[];
|
|
$out["internal_return"] = "100";
|
|
$out["firstname"] = "firstname";
|
|
$out["lastname"] = "lastname";
|
|
$out["session"] = "3333333777FFFFFFFFFFJJJJJJJJKKGFFFF";
|
|
$out["session_contructed"] = "3333333777FFFFFFFFFFJJJJJJJJKKGFFFF";
|
|
$out["username"] = "";
|
|
$out["last_login"] = "10-10-2021";
|
|
$out["member_id"] = "1";
|
|
$out["balance"] = "1000";
|
|
$out["added"] = "added";
|
|
$out["account_added"] = "10-10-2021";
|
|
$out["city"] = "Powder Springs";
|
|
$out["country"] = "US";
|
|
|
|
$out["email"] = "test@float.sg";
|
|
$out["fb_id"] = "";
|
|
$out["id"] = "1";
|
|
$out["loc"] = "192.168.1.1";
|
|
$out["news"] = "";
|
|
$out["phone"] = "";
|
|
$out["post_jobs"] = "";
|
|
$out["profile_pic"] = "";
|
|
$out["refer"] = "";
|
|
$out["state"] = "GA";
|
|
$out["status"] = "1";
|
|
$out["street1"] = "4202 defoors farm";
|
|
$out["zipcode"] = "30127";
|
|
$out["test"] = "0";
|
|
$out["points"] = "600000";
|
|
$out["min_budget"] = "10";
|
|
$out["max_budget"] = "10000";
|
|
$out["prompt_background_gps"] = "1";
|
|
return $out;
|
|
|
|
}
|
|
|
|
}
|