Upodated end points

This commit is contained in:
2023-01-28 21:26:36 -05:00
parent 09ddf68c75
commit eadd740484
7 changed files with 228 additions and 19 deletions
+9 -1
View File
@@ -46,7 +46,12 @@ $routes->get('/en/desktop/api/v2/myfit/blogdata', 'Myfit::blogdata'); // when n
$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');
//reset pass & login
$routes->post('/en/desktop/api/v2/myfit/resetpass', 'Myfit::resetpass');
//MYFIT DESKTOP USERS
//-- login
$routes->post('/en/desktop/api/v2/myfituser/login', 'Myfituser::users');
@@ -59,6 +64,7 @@ $routes->get('/en/desktop/api/v2/myfituser/myfeed', 'Myfituser::users');
$routes->get('/en/desktop/api/v2/myfituser/tracking', 'Myfituser::users');
$routes->get('/en/desktop/api/v2/myfituser/reminders', 'Myfituser::users');
$routes->get('/en/desktop/api/v2/myfituser/calendar', 'Myfituser::users');
$routes->get('/en/desktop/api/v2/myfituser/loginhx', 'Myfituser::users');
//MYFIT DESKTOP USERS
@@ -66,6 +72,8 @@ $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/mobile/api/v2/myfituser/reminders', 'Myfituser::users');
+20
View File
@@ -138,6 +138,26 @@ 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 ");
+32 -15
View File
@@ -17,7 +17,7 @@ class Myfituser extends BaseController
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 ');
@@ -27,12 +27,11 @@ class Myfituser extends BaseController
$mBlogData = new \App\Models\myfitBlogData();
$res1 = $mBlogData->getBlogData([]);
return $this->response->setJson($res1);
return $this->response->setJson($res1);*/
}
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');
@@ -49,8 +48,13 @@ class Myfituser extends BaseController
$endpoint = $psc > 0 ? $pieces[$psc - 1] : '';
$endpoints = [
'createuser' => ['POST'],
'account' => ['POST'],
'login' => ['POST'],
'reminders' => ['GET'],
'myfeed' => ['GET'],
'calendar' => ['GET'],
'profile' => ['GET'],
'loginhx' => ['GET'],
];
$res1 = [];
@@ -65,28 +69,41 @@ class Myfituser extends BaseController
$raw_array = json_decode($raw_json, true);
switch ($endpoint) {
case "login":
case 'login':
$userAccess = new \App\Models\userAccess();
$res1 = $userAccess->startLogin($raw_array);
break;
case "createuser":
$res= $this->dummyData($raw_array);
case 'account':
$res = $this->dummyData($raw_array);
break;
case 2:
echo "i equals 2";
case 'reminders':
$myfitUserReminders = new \App\Models\myfitUserReminders();
$res1 = $myfitUserReminders->readReminders($raw_array);
break;
case 'myfeed':
$res = $this->dummyData($raw_array);
break;
case 'calendar':
$res = $this->dummyData($raw_array);
break;
case 'profile':
$res = $this->dummyData($raw_array);
break;
case 'loginhx':
$myfitHx = new \App\Models\myfitHx();
$res1 = $myfitHx->readLoginHx($raw_array);
break;
}
return $this->response->setJson($res1);
}
//this is dummy function to establish the endpoints before real implementations
private function dummyData($raw_array){
//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
'msg' => 'Not implemented yet',
'raw_data' => $raw_array,
];
}
public function blogdata()
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
class myfitHx extends Model
{
protected $db;
public $con_name = 'mermsemr';
public function __construct()
{
parent::__construct();
$this->db = \Config\Database::connect($this->con_name);
}
public function readLoginHx($in)
{
$sqlQ =
'SELECT * FROM members_login_hx WHERE member_id='.$in['member_id'];
$query = $this->db->query($sqlQ);
$data['loginhx_data'] = $query->getResultArray();
return $inx = [
'loginhx' => $data['loginhx_data'],
'status' => 1,
'raw_data' => $in,
];
}
}
+46
View File
@@ -0,0 +1,46 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
class myfitTracking extends Model
{
protected $db;
public $con_name = 'mermsemr';
public function __construct()
{
parent::__construct();
//$db = \Config\Database::connect('mermsemr');
$this->db = \Config\Database::connect($this->con_name);
}
public function readTracking($in)
{
$sqlQ =
'SELECT * FROM members_reminders';
$query = $this->db->query($sqlQ);
$data['reminders_data'] = $query->getResultArray();
return $inx = [
'reminders' => $data['reminders_data'],
'status' => 1,
'raw_data' => $in,
];
}
public function getSupportedTrackingDevices(){
return [];
}
public function userConfigureDevice(){
return [];
}
}
+38
View File
@@ -0,0 +1,38 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
class myfitUserReminders extends Model
{
protected $db;
public $con_name = 'mermsemr';
public function __construct()
{
parent::__construct();
//$db = \Config\Database::connect('mermsemr');
$this->db = \Config\Database::connect($this->con_name);
}
public function readReminders($in)
{
$reminder_category =[];
$sqlQ =
'SELECT * FROM members_reminders';
$query = $this->db->query($sqlQ);
$data['reminders_data'] = $query->getResultArray();
return $inx = [
'reminder_category' => $reminder_category,
'reminders' => $data['reminders_data'],
'status' => 1,
'raw_data' => $in,
];
}
}
+52 -3
View File
@@ -22,8 +22,7 @@ class userAccess extends Model
$username = $in['username'];
$password = $in['password'];
$sqlQ =
"SELECT m.id as member_id, m.*,mp.*
$sqlQ = "SELECT m.id as member_id, m.*,mp.*
FROM members m LEFT
JOIN members_profile mp ON m.id=mp.member_id
WHERE LOWER(m.username) = LOWER('$username')
@@ -35,9 +34,11 @@ class userAccess extends Model
if (count($data['profile_data']) == 1) {
$data['profile_data'][0]['password'] = '**REMOVED**';
$member_id = $data['profile_data'][0]['member_id'];
$member_uid = $data['profile_data'][0]['uuid'];
return $inx = [
'session_token' => $this->generateSession($member_id),
'member_id' => $member_id,
'member_uuid' => $member_uid,
'profile' => $data['profile_data'][0],
'settings' => [],
'preferences' => [],
@@ -56,13 +57,61 @@ class userAccess extends Model
}
}
private function generateSession()
private function generateSession($member_id)
{
$loc = $this->getIPAddress();
// do the seesion stuffs here - set up all permissions
$tk = '';
for ($i = 1; $i < 20; $i++) {
$tk .= rand(11111, 99999);
}
$sqlQ = "DELETE FROM members_session WHERE member_id = $member_id ";
$query = $this->db->query($sqlQ);
$sqlQ =
"INSERT INTO members_session (session,member_id,loc) VALUES('" .
$tk .
"'," .
$member_id .
",'" .
$loc .
"'
) ";
$query = $this->db->query($sqlQ);
// Create HX
$sqlQ =
"INSERT INTO members_login_hx (member_id,channel,loc) VALUES ($member_id,'Desktop','" .
$loc .
"')";
$this->db->query($sqlQ);
return $tk;
}
private function getIPAddress()
{
//whether ip is from the share internet
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
}
//whether ip is from the proxy
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
//whether ip is from the remote address
else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
}
/*
CREATE TABLE members_login_hx (
id SERIAL,
member_id INT REFERENCES members(id) NOT NULL,
channel VARCHAR(15),
added timestamp without time zone DEFAULT now(),
loc INET
);
ALTER TABLE ONLY members_login_hx
ADD CONSTRAINT members_login_hx_id_key UNIQUE (id);*/