From f77766a2097e613673befc750ca707eb2cc8e6b2 Mon Sep 17 00:00:00 2001 From: "CHIEFSOFT\\ameye" Date: Sat, 8 Jul 2023 16:41:20 -0400 Subject: [PATCH] Wrench ouuth --- www-api/app/Config/Routes.php | 7 +- www-api/app/Controllers/WrenchOauth.php | 104 +++++++++++++++++++++++- 2 files changed, 109 insertions(+), 2 deletions(-) diff --git a/www-api/app/Config/Routes.php b/www-api/app/Config/Routes.php index 46f06852..9905e5f7 100644 --- a/www-api/app/Config/Routes.php +++ b/www-api/app/Config/Routes.php @@ -39,6 +39,12 @@ $routes->get('/', 'Home::index'); $routes->get('/en/wrench/api/v1/test','Home::test'); + + +$routes->post('/en/wrench/api/v1/authlogin', 'WrenchOauth::apigate'); +$routes->post('/en/wrench/api/v1/authstart', 'WrenchOauth::apigate'); + + $routes->post('/en/wrench/api/v1/faq', 'WrenchFaq::apigate'); $routes->post('/en/wrench/api/v1/faqdata', 'WrenchFaq::apigate'); $routes->post('/en/wrench/api/v1/mynotifications', 'WrenchApi::apigate'); @@ -58,7 +64,6 @@ $routes->post('/en/wrench/api/v1/completemobileuser', 'WrenchApi::apigate'); $routes->post('/en/wrench/api/v1/startresetpasword', 'WrenchApi::apigate'); $routes->post('/en/wrench/api/v1/userlogin', 'WrenchApi::apigate'); -$routes->post('/en/wrench/api/v1/authlogin', 'WrenchApi::apigate'); $routes->post('/en/wrench/api/v1/homebanners', 'WrenchApi::apigate'); $routes->post('/en/wrench/api/v1/startjoblist', 'WrenchApi::apigate'); diff --git a/www-api/app/Controllers/WrenchOauth.php b/www-api/app/Controllers/WrenchOauth.php index 3abfecaa..4c7f8e71 100644 --- a/www-api/app/Controllers/WrenchOauth.php +++ b/www-api/app/Controllers/WrenchOauth.php @@ -19,10 +19,112 @@ class WrenchOauth extends BaseController $envID = getenv('ENV_ID'); } + public function apigate(){ log_message('critical', "Oauth-Gate"); + header('Access-Control-Allow-Origin: *'); + log_message('critical', "0002"); + $call_backend = true; - return []; + header("Access-Control-Allow-Headers: Origin, X-API-KEY, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method, Access-Control-Allow-Headers, Authorization, observe, enctype, Content-Length, X-Csrf-Token"); + log_message('critical', "0003"); + header("Access-Control-Allow-Methods: GET, PUT, POST, DELETE, PATCH, OPTIONS"); + header("Access-Control-Allow-Credentials: true"); + header("Access-Control-Max-Age: 3600"); + header('content-type: application/json; charset=utf-8'); + $method = $_SERVER['REQUEST_METHOD']; + if ($method == "OPTIONS") { + header("HTTP/1.1 200 OK CORS"); + log_message('critical', " apigate()-> OPTIONS DIE*****" ); + die(); + } + + //$request = service('request'); + // 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 = $this->endPointList(); + $out = array(); + $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); + + $local_out =[]; + if ($_SERVER["REQUEST_METHOD"] == "POST") { // if upload lets modify all the data + if (isset($_FILES) && is_array($_FILES) && count($_FILES)>0) { + $raw_array = array_merge($_POST,$_FILES); + } + } + + 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):[]; + } + //$in = $raw_array; + log_message('critical', "wrenchboard_api-CALL RAW DATA".serialize($raw_array) ); + //-- move to another module start + + + $in["loc"] = $_SERVER["REMOTE_ADDR"]; + $in = $this->prepareOauthEndPointData($endpoint, $raw_array,$call_backend,$local_out); + log_message('critical', "wrenchboard_api-CALL PREPARE DATA".serialize($in) ); + + + if ( $call_backend == true && $in["action"] !='' ){ + $wrenchboard = new \App\Models\BackendModel(); + $ret = $wrenchboard->wrenchboard_api($in, $out); + $out['internal_return'] = $ret; + } + else + { + $out = $local_out; + } + + //$this->doCacheStep($in, $out); + return json_encode( ( new \App\Models\ResultFormatter() )->processOutJson($in, $out)); + + } + + private function prepareOauthEndPointData($endpoint, $in, &$call_backend=true,&$local_out=[]){ + switch ($endpoint) { + case 'authstart ': + + + + $call_backend=false; + break; + case 'authlogin': + $in["action"] = WRENCHBOARD_ACCOUNT_AUXLOGIN; + if (!isset($in["login_mode"])){ + $in["login_mode"] = MOBILE_LOGIN; + } + break; + } + $in["pid"] = 100; + return $in; } } \ No newline at end of file