request = $request = \Config\Services::request(); } public function index() { $data['envID'] = getenv('ENV_ID'); $data['home_background'] = getenv('HOME_PAGE_BACKGROUND'); return view('welcome_message',$data); } public function apigate(){ /* //$request = service('request'); header('Access-Control-Allow-Origin: *'); //header("Access-Control-Allow-Origin: http://localhost:9057 "); header('Access-Control-Expose-Headers: Access-Control-Allow-Origin'); //header('Access-Control-Allow-Credentials: true '); //header("Access-Control-Allow-Headers: Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With"); header('Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS'); header('Content-type: application/json'); */ // what is the endpoint $uri = urldecode(current_url(true)); $findme = '?'; $pos = strpos($uri, $findme); if ($pos > 5) { $uri = substr($uri, 0, $pos); } log_message('critical', "API-GATE URI -> ".$uri ); $pieces = explode('/', $uri); $psc = count($pieces); $endpoint = $psc > 0 ? $pieces[$psc - 1] : ''; log_message('critical', "Enpoint-> ".$endpoint ); $endpoints = [ 'apigate' => ['POST'], 'generics' => ['POST'], 'createuser' => ['POST'], 'createmobileuser' => ['POST'], 'completemobileuser' => ['POST'], 'startresetpasword' => ['POST'], 'userlogin' => ['POST'], 'startjoblist' => ['POST'], 'dashdata' => ['POST'], 'getjobsdata' => ['POST'], 'offerslist' => ['POST'], 'activejoblist' => ['POST'], 'loadprofile' => ['POST'], 'account' => ['POST'], 'message' => ['POST'], 'pendingjob' => ['POST'], 'paymenthx' => ['POST'], 'getjob' => ['POST'], 'mybanklist' => ['POST'], 'sendmoney' => ['POST'], 'sendinterest' => ['POST'], 'sendmoneyfee' => ['POST'], 'getpendingjobs' => ['POST'], 'taskmessage' => ['POST'], 'sendtaskmessage' => ['POST'], 'getwallets' => ['POST'], 'sitecontact' => ['POST'], 'signupcountry' => ['POST'], 'userscards' => ['POST'], 'blogdata' => ['POST'], 'blogitem' => ['POST'], 'couponhx' => ['POST'], 'couponpending' => ['POST'], 'couponredeem' => ['POST'], 'sendinterestmessage' => ['POST'], 'replyinterestmessage' => ['POST'], 'disableaccount' => ['POST'], 'myjobs' => ['POST'] ]; $res1 = []; if (array_key_exists($endpoint, $endpoints)) { } else { http_response_code(404); // tell the user product does not exist echo json_encode([ 'message' => 'Endpoint not found.', 'URI' => $uri, ]); } // echo "EXYTACT INPUT DATA HERE"; $raw_json = file_get_contents('php://input'); $raw_array = json_decode($raw_json, true); if ($_SERVER['REQUEST_METHOD'] == 'GET') { log_message('critical', "Enpoint LOC2 HERE -> ".$endpoint ); $get_param = $_GET['reqData'] ?? null; $raw_array = ($get_param!=null) ? json_decode($get_param, true):[]; } //-- move to another module start $call_backend = true; $in["loc"] = $_SERVER["REMOTE_ADDR"]; switch ($endpoint) { case 'disableaccount': $in['action'] = WRENCHBOARD_USER_DELETEACC; break; case 'replyinterestmessage': $in["action"] = WRENCHBOARD_JOB_REPLY_QUESTION; break; case 'sendinterestmessage': // $in['offer_code'] = $this->input->get('offer_code'); $in['yourmessage'] = $in["question"]; //$in['member_id'] = $_SESSION['member_id']; // just maing sure $in['msg_type'] = 'JOB'; // $in['action'] = WRENCHBOARD_JOB_SEND_QUESTION; $in["action"] = WRENCHBOARD_JOB_SEND_QUESTION; break; case 'couponredeem': $in["action"] = WRENCHBOARD_COUPON_REDEEM; break; case 'couponpending': $in["action"] = WRENCHBOARD_COUPON_PENDLIST; break; case 'couponhx': $in["action"] = WRENCHBOARD_COUPON_MEMLIST; break; case 'signupcountry': // checi if in cache if not read $local_out = [ 'result'=>'100', 'signup_country'=>[ ['NG', 'Nigeria'], ['US', 'United States'] ] ]; $call_backend = false; break; case 'blogitem': $blogData = getBlogItem(); $local_out = [ 'result'=>'100', 'blog_data'=> $blogData ]; $call_backend = false; break; case 'blogdata': $blogData = getBlogData(); $local_out = [ 'result'=>'100', 'blog_data'=> $blogData ]; $call_backend = false; break; case 'userscards': $in["action"] = WRENCHBOARD_CARDS_GETCARDLIST; $local_out = [ 'result'=>'100', 'result_list'=>[ ['title'=>'This is your coupon', 'description'=>'This is the description of the description', 'card_type'=>'COUPON', 'card_style' =>'card1', 'card_icon' =>'icon1', 'assign_id'=> 0, 'Nigeria'], ['title'=>'A Recommended Story', 'description'=>'This is the description of the description', 'card_type'=>'BLOG', 'card_style' =>'card2', 'card_icon' =>'icon1', 'assign_id'=> 0, 'United States'], ['title'=>'You have a new task sent to you', 'description'=>'This is the description of the description', 'card_type'=>'NEWTASK', 'card_style' =>'card1', 'card_icon' =>'icon1', 'assign_id'=> 0, 'United States'], ['title'=>'You just Earned some token', 'description'=>'This is the description of the description', 'card_type'=>'TOKEN', 'card_style' =>'card2', 'card_icon' =>'icon1', 'assign_id'=> 0, 'United States'] ] ]; // $call_backend = false; break; case 'myjobs': $in["action"] = WRENCHBOARD_ACCOUNT_JOBLIST; break; case 'sitecontact': $local_out = ['result'=>'100','msg'=>'Received']; $call_backend = false; break; case 'generics': case 'apigate': //$in["action"] = WRENCHBOARD_ACCOUNT_LOGIN; break; case 'startjoblist': $in["action"] = WRENCHBOARD_START_JOBLIST; if (!array_key_exists("limit",$in)) $in["limit"] = 10; if (!array_key_exists("page",$in)) $in["page"] = 1; break; case 'createmobileuser': $in["action"] = WRENCHBOARD_CREATE_MOBILEUSER; $in["loc"] = $_SERVER["REMOTE_ADDR"]; $in["news"] = 0; $in["terms"] = 1; $in["mobile"] = "MOBILE"; break; case 'completemobileuser': $in["action"] = WRENCHBOARD_COMPLETE_MOBILEUSER; $in["loc"] = $_SERVER["REMOTE_ADDR"]; break; case 'startresetpasword': $in["action"] = WRENCHBOARD_RESET_PASSWORD; break; case 'createuser': $in["action"] = WRENCHBOARD_ACCOUNT_PENDING; $in["street1"] = $in["streetaddress"]; $in["zipcode"] = $in["zip"]; $in["country"] = "US"; $in["loc"] = $_SERVER["REMOTE_ADDR"]; $in["mobile"] = "MOBILE"; break; case 'activejoblist': $in["action"] = WRENCHBOARD_MOBILE_ACTIVEJOB; break; case 'message': $in["action"] = WRENCHBOARD_MOBILE_MESSAGE; break; case 'paymenthx': $in["action"] = WRENCHBOARD_MOBILE_PAYMENTHX; break; case 'getjobsdata': $in["action"] = WRENCHBOARD_ACCOUNT_JOBLIST; break; case 'userlogin': $in["action"] = WRENCHBOARD_ACCOUNT_LOGIN; $in["login_mode"] = MOBILE_LOGIN; break; case 'dashdata': $in["action"] = WRENCHBOARD_ACCOUNT_DASHDATA; break; case 'offerslist': $in["action"] = WRENCHBOARD_MOBILE_OFFERSLIST; break; case 'loadprofile': $in["action"] = WRENCHBOARD_MOBILE_LOADPROFILE; break; case 'account': $in["action"] = WRENCHBOARD_MOBILE_ACCOUNT; break; case 'getpendingjobs': $in["action"] = WRENCHBOARD_ACCOUNT_PENDJOB; break; case 'pendingjob': break; case 'getjob': break; case 'mybanklist':$in["action"] = WRENCHBOARD_USER_GETBANKLIST; break; case 'sendmoney':$in["action"] = WRENCHBOARD_USER_SENDMONEY; $out["internal_return"] = 0; break; case 'sendinterest':$in["action"] = WRENCHBOARD_USER_SENDJOBINT; $out["internal_return"] = 0; break; case 'sendmoneyfee': $in["action"] = WRENCHBOARD_SMONEY_PROCFEE; break; case 'taskmessage': $in["action"] = WRENCHBOARD_MOBILE_TASKMESSAGE; break; case 'sendtaskmessage': $in["action"] = WRENCHBOARD_MOBILE_SENDTASKMESSAGE; break; case 'getwallets': $in["action"] = WRENCHBOARD_ACCOUNT_WALLETS; break; } //-- move to another module end $in["pid"] = 100; $out = array(); if ( $call_backend == true){ $wrenchboard = new \App\Models\BackendModel(); $ret = $wrenchboard->wrenchboard_api($in, $out); $out['internal_return'] = 0; // $ret; // this is reserved array parameter - to be captured and received before you use the out array() } else { $out = $local_out; } //ResultFormatter return json_encode( ( new \App\Models\ResultFormatter() )->processOutJson($in, $out)); // $res1 = $this->dummyData($raw_array); // return $this->response->setJson($res1); } private function dummyData($raw_array) { return [ 'msg' => 'Not implemented yet', 'raw_data' => $raw_array, ]; } }