From dde19194906b3fa4a8bf3efc24d25b10585e3276 Mon Sep 17 00:00:00 2001 From: "DESKTOP-BC3NEC6\\chiefsoft" Date: Sat, 28 Jan 2023 21:34:29 -0500 Subject: [PATCH] Myfit auth added --- app/Config/Routes.php | 9 ++-- app/Controllers/Myfit.php | 21 +-------- app/Controllers/Myfitauth.php | 83 +++++++++++++++++++++++++++++++++++ app/Controllers/Myfituser.php | 6 +-- 4 files changed, 90 insertions(+), 29 deletions(-) create mode 100644 app/Controllers/Myfitauth.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 1f905c7..1fbbc4a 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -48,15 +48,12 @@ $routes->post('/en/desktop/api/v2/myfit/contact', 'Myfit::contact'); $routes->get('/en/desktop/api/v2/myfit/pricing', 'Myfit::pricing'); //reset pass & login -$routes->post('/en/desktop/api/v2/myfit/resetpass', 'Myfit::resetpass'); - - - +$routes->post('/en/desktop/api/v2/myfituser/resetpass', 'Myfitauth::resetpass'); //MYFIT DESKTOP USERS //-- login -$routes->post('/en/desktop/api/v2/myfituser/login', 'Myfituser::users'); +$routes->post('/en/desktop/api/v2/myfituser/login', 'Myfitauth::users'); //--create acount -$routes->post('/en/desktop/api/v2/myfituser/account', 'Myfituser::users'); +$routes->post('/en/desktop/api/v2/myfituser/account', 'Myfitauth::users'); $routes->get('/en/desktop/api/v2/myfituser/profile', 'Myfituser::users'); diff --git a/app/Controllers/Myfit.php b/app/Controllers/Myfit.php index 5b8519f..058fcb8 100644 --- a/app/Controllers/Myfit.php +++ b/app/Controllers/Myfit.php @@ -138,26 +138,7 @@ class Myfit extends BaseController return $this->response->setJson($mCountry->getSiteCountries([])); } - public function resetpass(){ - //header("Access-Control-Allow-Origin: http://localhost:9057 "); - header('Access-Control-Allow-Origin: * '); - 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'); - - $raw_json = file_get_contents('php://input'); - $raw_array = json_decode($raw_json, true); - - $res1 = [ - 'email' => $raw_array['email'], - 'status' => 1 - ]; - return $this->response->setJson($res1); - - } - + public function faq() { //header("Access-Control-Allow-Origin: http://localhost:9057 "); diff --git a/app/Controllers/Myfitauth.php b/app/Controllers/Myfitauth.php new file mode 100644 index 0000000..6e4b745 --- /dev/null +++ b/app/Controllers/Myfitauth.php @@ -0,0 +1,83 @@ +request = $request = \Config\Services::request(); + } + + public function index() + { + } + + public function users() + { + 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 = current_url(true); + $pieces = explode('/', $uri); + $psc = count($pieces); + + $endpoint = $psc > 0 ? $pieces[$psc - 1] : ''; + + $endpoints = [ + 'account' => ['POST'], + 'login' => ['POST'], + 'resetpass' => ['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.']); + } + // echo "EXYTACT INPUT DATA HERE"; + $raw_json = file_get_contents('php://input'); + $raw_array = json_decode($raw_json, true); + + switch ($endpoint) { + case 'login': + $userAccess = new \App\Models\userAccess(); + $res1 = $userAccess->startLogin($raw_array); + break; + case 'account': + $res1 = $this->dummyData($raw_array); + break; + + case 'resetpass': + $res1 = [ + 'email' => $raw_array['email'], + 'status' => 1, + ]; + } + + return $this->response->setJson($res1); + } + + //this is dummy function to establish the endpoints before real implementations + private function dummyData($raw_array) + { + return [ + 'msg' => 'Not implemented yet', + 'raw_data' => $raw_array, + ]; + } +} diff --git a/app/Controllers/Myfituser.php b/app/Controllers/Myfituser.php index 4e47340..02bb1e0 100644 --- a/app/Controllers/Myfituser.php +++ b/app/Controllers/Myfituser.php @@ -70,11 +70,11 @@ class Myfituser extends BaseController switch ($endpoint) { case 'login': - $userAccess = new \App\Models\userAccess(); - $res1 = $userAccess->startLogin($raw_array); + // $userAccess = new \App\Models\userAccess(); + // $res1 = $userAccess->startLogin($raw_array); break; case 'account': - $res = $this->dummyData($raw_array); + // $res = $this->dummyData($raw_array); break; case 'reminders': $myfitUserReminders = new \App\Models\myfitUserReminders();