myfir-login

This commit is contained in:
2023-01-25 19:06:17 -05:00
parent ec63e35f70
commit 538bada3ad
3 changed files with 123 additions and 77 deletions
+7 -1
View File
@@ -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');
+59 -76
View File
@@ -1,6 +1,5 @@
<?php
namespace App\Controllers;
use CodeIgniter\HTTP\RequestInterface;
@@ -16,15 +15,14 @@ class Myfituser extends BaseController
$this->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);
}
}
}
+57
View File
@@ -0,0 +1,57 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
class userAccess 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 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;
}
}