From 538bada3ada0a6f93b545b3a686d92d222c87a8d Mon Sep 17 00:00:00 2001 From: "DESKTOP-BC3NEC6\\chiefsoft" Date: Wed, 25 Jan 2023 19:06:17 -0500 Subject: [PATCH] myfir-login --- app/Config/Routes.php | 8 +- app/Controllers/Myfituser.php | 135 +++++++++++++++------------------- app/Models/userAccess.php | 57 ++++++++++++++ 3 files changed, 123 insertions(+), 77 deletions(-) create mode 100644 app/Models/userAccess.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 49bfaf3..e15cb0c 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -47,10 +47,16 @@ $routes->get('/en/desktop/api/v2/myfit/faq', 'Myfit::faq'); $routes->post('/en/desktop/api/v2/myfit/contact', 'Myfit::contact'); $routes->get('/en/desktop/api/v2/myfit/pricing', 'Myfit::pricing'); -//MYFIT USERS +//MYFIT DESKTOP USERS $routes->post('/en/desktop/api/v2/myfituser/login', 'Myfituser::users'); $routes->post('/en/desktop/api/v2/myfituser/account', 'Myfituser::users'); +//MYFIT DESKTOP USERS +$routes->post('/en/mobile/api/v2/myfituser/login', 'Myfituser::users'); +$routes->post('/en/mobile/api/v2/myfituser/account', 'Myfituser::users'); +$routes->get('/en/mobile/api/v2/myfit/blogdata', 'Myfit::blogdata'); + + $routes->get('/en/desktop/api/v2/myfituser/profile', 'Myfituser::users'); $routes->get('/en/desktop/api/v2/myfituser/myfeed', 'Myfituser::users'); diff --git a/app/Controllers/Myfituser.php b/app/Controllers/Myfituser.php index 1f418b3..d741a1b 100644 --- a/app/Controllers/Myfituser.php +++ b/app/Controllers/Myfituser.php @@ -1,6 +1,5 @@ request = $request = \Config\Services::request(); } - public function index() { - header("Access-Control-Allow-Origin: * "); + 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-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('Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS'); header('Content-type: application/json'); $mBlogData = new \App\Models\myfitBlogData(); @@ -34,63 +32,47 @@ class Myfituser extends BaseController public function users() { - header("Access-Control-Allow-Origin: * "); + 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-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('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); + // what is the endpoint + $uri = current_url(true); + $pieces = explode('/', $uri); + $psc = count($pieces); - $endpoint = ( $psc > 0) ? $pieces[ $psc-1] : ''; + $endpoint = $psc > 0 ? $pieces[$psc - 1] : ''; - $endpoints = array( - 'createuser' => array('POST'), - 'userlogin' => 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.")); - } - - - $raw_json = file_get_contents("php://input"); - $raw_array = json_decode($raw_json, true); - // $something = $raw_array["name"]; - - $sqlQ = "SELECT m.*,mp.* FROM members m LEFT JOIN members_profile mp ON m.id=mp.member_id WHERE m.id =12"; - $db = \Config\Database::connect('mermsemr'); - $query = $db->query( $sqlQ ); - $data['test_data'] = $query->getResultArray(); - - - $inx = [ - 'message_id' => rand(100, 8888) . 'gsgsgsgsg-sssfsgggsgs-ususususu', - 'test'=> $sqlQ, - 'test_data' => $data['test_data'], - 'status'=>1, - 'endpoint'=>$endpoint, - 'raw_data'=> $raw_array + $endpoints = [ + 'createuser' => ['POST'], + 'login' => ['POST'], ]; - return $this->response->setJson($inx); - } + // $raw_array = []; + if (array_key_exists($endpoint, $endpoints)) { + } else { + http_response_code(404); + // tell the user product does not exist + echo json_encode(['message' => 'Enpoint not found.']); + } + // echo "EXYTACT INPUT DATA HERE"; + $raw_json = file_get_contents('php://input'); + $raw_array = json_decode($raw_json, true); + + + $userAccess = new \App\Models\userAccess(); + $res1 = $userAccess->startLogin($raw_array); + + return $this->response->setJson($res1); + } public function blogdata() { - /* header("Access-Control-Allow-Origin: *"); + /* header("Access-Control-Allow-Origin: *"); //header("x-devicetoken : *"); //header("Authorization : Token"); header("Access-Control-Expose-Headers: Access-Control-Allow-Origin"); @@ -103,28 +85,28 @@ class Myfituser extends BaseController header2 = ('Access-Control-Allow-Origin', 'https://serviceview.example.com') */ - header("Access-Control-Allow-Origin: * "); + 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-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('Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS'); header('Content-type: application/json'); $mBlogData = new \App\Models\myfitBlogData(); $res1 = $mBlogData->getBlogData([]); return $this->response->setJson($res1); - // $this->setGetReturn(res1); + // $this->setGetReturn(res1); } public function country() { //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-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('Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS'); header('Content-type: application/json'); $mCountry = new \App\Models\myfitCountry(); @@ -134,39 +116,40 @@ class Myfituser extends BaseController public function faq() { //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-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('Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS'); header('Content-type: application/json'); $mFaq = new \App\Models\myfitFaqData(); return $this->response->setJson($mFaq->getSiteFaq([])); } - + public function pricing() { //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-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('Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS'); header('Content-type: application/json'); $mPricing = new \App\Models\myfitPricing(); return $this->response->setJson($mPricing->getSitePricing([])); } - private function setGetReturn($resp){ - header("Access-Control-Allow-Origin: * "); + private function setGetReturn($resp) + { + 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-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('Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS'); header('Content-type: application/json'); return $this->response->setJson($resp); } -} \ No newline at end of file +} diff --git a/app/Models/userAccess.php b/app/Models/userAccess.php new file mode 100644 index 0000000..93b48c8 --- /dev/null +++ b/app/Models/userAccess.php @@ -0,0 +1,57 @@ +db = \Config\Database::connect($this->con_name); + } + + public function startLogin($in) + { + $sqlQ = + 'SELECT m.*,mp.* FROM members m LEFT JOIN members_profile mp ON m.id=mp.member_id WHERE m.id =12'; + $query = $this->db->query($sqlQ); + $data['test_data'] = $query->getResultArray(); + + if (count($data['test_data']) == 1) { + $data['test_data'][0]['password'] = '**REMOVED**'; + $member_id = $data['test_data'][0]['id']; + return $inx = [ + 'session_token' => $this->generateSession($member_id), + 'member_id'=> $member_id, + 'profile' => $data['test_data'], + 'settings' => [], + 'preferences' => [], + 'status' => 1, + 'raw_data' => $in, + ]; + } else { + return $inx = [ + 'session_token' => '', + 'settings' => [], + 'preferences' => [], + 'status' => 0, + 'raw_data' => $in, + ]; + } + } + + private function generateSession() + { + // do the seesion stuffs here - set up all permissions + $tk=''; + for($i=1; $i<20; $i++){ + $tk .= rand(11111, 99999); + } + return $tk; + } +}