diff --git a/app/Config/Database.php b/app/Config/Database.php index 775953d..26851be 100644 --- a/app/Config/Database.php +++ b/app/Config/Database.php @@ -70,6 +70,26 @@ class Database extends Config 'port' => 5432, ]; + public $myfit = [ + 'DSN' => '', + 'hostname' => '10.20.30.60', + 'username' => 'myfit', + 'password' => 'myfit', + 'database' => 'myfit_dev', + 'DBDriver' => 'postgre', + 'DBPrefix' => '', + 'pConnect' => false, + 'DBDebug' => (ENVIRONMENT !== 'production'), + 'charset' => 'utf8', + 'DBCollat' => 'utf8_general_ci', + 'swapPre' => '', + 'encrypt' => false, + 'compress' => false, + 'strictOn' => false, + 'failover' => [], + 'port' => 5432, + ]; + public $mermsemr_blog = [ 'DSN' => '', 'hostname' => '10.10.33.60', @@ -147,5 +167,9 @@ class Database extends Config if (ENVIRONMENT === 'testing') { $this->defaultGroup = 'tests'; } + $this->myfit['hostname'] = getenv('MYFIT_DATABASE_HOSTNAME'); + $this->myfit['username'] = getenv('MYFIT_DATABASE_USERNAME'); + $this->myfit['password'] = getenv('MYFIT_DATABASE_PASSWORD'); + $this->myfit['database'] = getenv('MYFIT_DATABASE'); } } diff --git a/app/Config/Email.php b/app/Config/Email.php index 3a42fbe..c764406 100644 --- a/app/Config/Email.php +++ b/app/Config/Email.php @@ -33,8 +33,8 @@ class Email extends BaseConfig * * @var string */ - public $protocol = 'mail'; - + //public $protocol = 'mail'; + public $protocol = 'smtp'; /** * The server path to Sendmail. * @@ -47,28 +47,32 @@ class Email extends BaseConfig * * @var string */ - public $SMTPHost; + //public $SMTPHost; + public $SMTPHost= 'smtp.google.com'; /** * SMTP Username * * @var string */ - public $SMTPUser; - + //public $SMTPUser; + public $SMTPUser='support@chiefsoft.com'; /** * SMTP Password * * @var string */ - public $SMTPPass; + //public $SMTPPass; + public $SMTPPass='may12002!'; + /** * SMTP Port * * @var int */ - public $SMTPPort = 25; + //public $SMTPPort = 25; + public $SMTPPort = 465; // 993; //465; /** * SMTP Timeout (in seconds) @@ -89,8 +93,8 @@ class Email extends BaseConfig * * @var string */ + //public $SMTPCrypto = 'tls'; public $SMTPCrypto = 'tls'; - /** * Enable word-wrap * diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 4210bf7..f88263e 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -58,13 +58,15 @@ $routes->post('/en/desktop/api/v2/myfituser/resetpass', 'Myfitauth::users'); $routes->post('/en/desktop/api/v2/myfituser/login', 'Myfitauth::users'); //--create acount $routes->post('/en/desktop/api/v2/myfituser/account', 'Myfitauth::users'); - +$routes->post('/en/desktop/api/v2/myfituser/signup-code', 'Myfitauth::users'); +$routes->post('/en/desktop/api/v2/myfituser/resetpass-code', 'Myfitauth::users'); $routes->get('/en/desktop/api/v2/myfituser/profile', 'Myfituser::users'); $routes->get('/en/desktop/api/v2/myfituser/myfeed', 'Myfituser::users'); //Tracking $routes->post('/en/desktop/api/v2/myfituser/tracking', 'Myfituser::users'); +$routes->get('/en/desktop/api/v2/myfituser/trackinghx', 'Myfituser::users'); $routes->get('/en/desktop/api/v2/myfituser/trackcategory', 'Myfituser::users'); // REMINDERS ------------------------------------------------------------- diff --git a/app/Controllers/Myfitauth.php b/app/Controllers/Myfitauth.php index 6e4b745..e4fee46 100644 --- a/app/Controllers/Myfitauth.php +++ b/app/Controllers/Myfitauth.php @@ -40,6 +40,8 @@ class Myfitauth extends BaseController 'account' => ['POST'], 'login' => ['POST'], 'resetpass' => ['POST'], + 'signup-code' => ['POST'], + 'resetpass-code' => ['POST'] ]; $res1 = []; @@ -59,19 +61,51 @@ class Myfitauth extends BaseController $res1 = $userAccess->startLogin($raw_array); break; case 'account': - $res1 = $this->dummyData($raw_array); + $userSignUp = new \App\Models\userSignUp(); + //$this->push(); + $res1 = $userSignUp->startSignUp($raw_array); break; case 'resetpass': - $res1 = [ - 'email' => $raw_array['email'], - 'status' => 1, - ]; + $passReset = new \App\Models\usersResetPass(); + $res1 = $passReset->startPassReset($raw_array); + break; + + case 'signup-code': + $userSignUp = new \App\Models\userSignUp(); + $res1 = $userSignUp->tempCodes(); + break; + + case 'resetpass-code': + $passReset = new \App\Models\usersResetPass(); + $res1 = $passReset->tempCodes(); + break; + } return $this->response->setJson($res1); } + public function push() + { + $to = 'ameye@chiefsoft.com';//Type here the mail address where you want to send + $subject = 'myFit Signup';//Write here Subject of Email + $message='Conngrats ! You did it.';//Write the message you want to send + $email = \Config\Services::email(); + $email->setTo($to); + $email->setFrom('works@chiefsoft.com', 'Just testing the emsil function');//set From + $email->setSubject($subject); + $email->setMessage($message); + if($email->send()) + { + //echo 'Email has been Sent.'; + log_message('critical', "Email has been Sent" ); + } + else{ + // echo 'Something went wrong !'; + log_message('critical', "Something went wrong" ); + } + } //this is dummy function to establish the endpoints before real implementations private function dummyData($raw_array) { diff --git a/app/Controllers/Myfituser.php b/app/Controllers/Myfituser.php index ea58ee7..58f4457 100644 --- a/app/Controllers/Myfituser.php +++ b/app/Controllers/Myfituser.php @@ -60,6 +60,7 @@ class Myfituser extends BaseController 'trackcategory' => ['GET'], 'resetpass' => ['POST'], 'tracking' => ['POST'], + 'trackinghx' => ['GET'] ]; $res1 = []; @@ -138,6 +139,10 @@ class Myfituser extends BaseController $myfitTracking = new \App\Models\myfitTracking(); $res1 = $myfitTracking->trackEngine($raw_array); break; + case 'trackinghx': + $myfitTracking = new \App\Models\myfitTracking(); + $res1 = $myfitTracking->readTracking($raw_array); + break; } return $this->response->setJson($res1); diff --git a/app/Models/baseModel.php b/app/Models/baseModel.php index 768f786..6209ab5 100644 --- a/app/Models/baseModel.php +++ b/app/Models/baseModel.php @@ -2,6 +2,8 @@ namespace App\Models; use CodeIgniter\Model; +use CodeIgniter\Database\RawSql; + class baseModel extends Model { @@ -12,27 +14,46 @@ class baseModel extends Model { parent::__construct(); $this->db = \Config\Database::connect($this->con_name); + log_message('critical', "BaseModel-Entered" ); } public function insert_db($inserDataArray, $insertTable) { - $insert_id=0; - $ic = 0; - $fl_part = ''; - $val_part = ''; - $sqlQ = ''; - $fields = array_keys($inserDataArray); - foreach ($fields as $field) { - $fl_part .= $ic > 0 ? ',' : ''; - $fl_part .= $field; + log_message('critical', "insert_db-WAS CALLED user 000=>" ); + $insert_id=0; + $ic = 0; + $fl_part = ''; + $val_part = ''; + $sqlQ = ''; + // try { + + $fields = array_keys($inserDataArray); + log_message('critical', "insert_db-WAS CALLED user 009a=>" ); + foreach ($fields as $field) { + $fl_part .= $ic > 0 ? ',' : ''; + $fl_part .= $field; + + $val_part .= $ic > 0 ? ',' : ''; + $val_part .= "'" . $inserDataArray[$field] . "'"; + $ic++; + } + log_message('critical', "insert_db-WAS CALLED user 009b=>" ); + $sqlQ = "INSERT INTO $insertTable ($fl_part) VALUES ($val_part)"; + log_message('critical', "SQL-WAS CALLED user =>". $sqlQ ); + $query = $this->db->query($sqlQ); + if(!$query){ + $insert_id=-1; + } + // $insert_id = $this->db->insert_id(); + // $insert_id = $this->db->getInsertID(); + // $this->db->insert($insertTable,$inserDataArray); + // $insert_id = $this->db->insert_id(); + // } catch (Exception $e) { + //echo 'Caught exception: ', $e->getMessage(), "\n"; + // log_message('critical', "Caught exception: => ".$e->getMessage() ); + // } - $val_part .= $ic > 0 ? ',' : ''; - $val_part .= "'" . $inserDataArray[$field] . "'"; - $ic++; - } - $sqlQ = "INSERT INTO $insertTable ($fl_part) VALUES ($val_part)"; - $query = $this->db->query($sqlQ); - $insert_id = $this->db->insert_id(); + return $insert_id; } public function update_db($UupdateDataArray,$whereAray, $updateTable) @@ -60,4 +81,21 @@ class baseModel extends Model $query = $this->db->query($sqlQ); return 0; } + + public 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; + } } diff --git a/app/Models/myfitHx.php b/app/Models/myfitHx.php index 8e2223b..ab1f32c 100644 --- a/app/Models/myfitHx.php +++ b/app/Models/myfitHx.php @@ -5,29 +5,29 @@ use CodeIgniter\Model; class myfitHx extends baseModel { - protected $db; - // public $con_name = 'mermsemr'; public function __construct() { parent::__construct(); - // $this->db = \Config\Database::connect($this->con_name); } public function readLoginHx($in) { // $in['member_id'] = 16; - $member_id = + $member_id2 = isset($in['member_id']) && $in['member_id'] > 0 && is_int($in['member_id']) ? $in['member_id'] : 0; - // $member_id = 13; + $member_id = isset($in["member_id"]) ? (int) $in["member_id"]: 0 ; + + $member_id = 13; $sqlQ = 'SELECT * FROM members_login_hx WHERE member_id=' . $member_id . ' ORDER BY id DESC LIMIT 15'; + log_message('critical', "readLoginHx=>".$sqlQ ); $query = $this->db->query($sqlQ); $data['loginhx_data'] = $query->getResultArray(); return $inx = [ diff --git a/app/Models/myfitTracking.php b/app/Models/myfitTracking.php index f23e394..acad246 100644 --- a/app/Models/myfitTracking.php +++ b/app/Models/myfitTracking.php @@ -23,12 +23,13 @@ class myfitTracking extends baseModel public function readTracking($in) { - $sqlQ = 'SELECT * FROM members_reminders'; - + $code_line = ( isset($in["code"]) && $in["code"] !='') ? " AND code= '".$in['code']."'" :''; + $member_id = isset($in["member_id"]) ? (int) $in["member_id"]: 0 ; + $sqlQ = "SELECT * FROM members_tracking WHERE member_id=$member_id $code_line"; $query = $this->db->query($sqlQ); - $data['reminders_data'] = $query->getResultArray(); + $data['tracking_data'] = $query->getResultArray(); return $inx = [ - 'reminders' => $data['reminders_data'], + 'tracking_data' => $data['tracking_data'], 'status' => 1, 'raw_data' => $in, ]; @@ -49,15 +50,31 @@ class myfitTracking extends baseModel switch($in['code']){ case "WEIGT": $inData = [ + 'code'=>$in['code'], 'member_id'=>$in['member_id'], - 'val1'=>$in['value'], + 'val1'=>$in['val1'], 'munit'=>$in['unit'], + 'event_time'=>$in['event_time'], + 'loc'=>$this->getIPAddress() ]; - $insert_id = $this->insert_db($inData, 'members_tracking_summary'); + $insert_id = $this->insert_db($inData, 'members_tracking'); break; + case 'BLPR': + $inData = [ + 'code'=>$in['code'], + 'member_id'=>$in['member_id'], + 'val1'=>$in['val1'], + 'val2'=>$in['val2'], + 'val3'=>$in['val3'], + 'munit'=>$in['unit'], + 'event_time'=>$in['event_time'], + 'loc'=>$this->getIPAddress() + ]; + $insert_id = $this->insert_db($inData, 'members_tracking'); + break; } - return ['insert_id'=> $insert_id, 'raw_data'=>$in ]; + return ['insert_id'=> $insert_id, 'raw_data'=>$in ,'inData'=> $inData]; } } diff --git a/app/Models/userAccess.php b/app/Models/userAccess.php index 1cc3148..1daed34 100644 --- a/app/Models/userAccess.php +++ b/app/Models/userAccess.php @@ -5,14 +5,11 @@ use CodeIgniter\Model; class userAccess extends baseModel { - protected $db; - // public $con_name = 'mermsemr'; + // protected $db; public function __construct() { parent::__construct(); - //$db = \Config\Database::connect('mermsemr'); - // $this->db = \Config\Database::connect($this->con_name); } public function startLogin($in) @@ -105,7 +102,7 @@ class userAccess extends baseModel return $tk; } - private function getIPAddress() + private function getIPAddress_old() { //whether ip is from the share internet if (!empty($_SERVER['HTTP_CLIENT_IP'])) { diff --git a/app/Models/userSignUp.php b/app/Models/userSignUp.php new file mode 100644 index 0000000..823b3a6 --- /dev/null +++ b/app/Models/userSignUp.php @@ -0,0 +1,90 @@ +encryptmd5($in["password"]); + $randomText = rand(1010101,999999);// rand(1010101,999999); + $inData =[ + 'username'=> $in["username"], + 'email'=> $in["email"], + 'password'=> $passEnr, + 'firstname'=> $in["firstname"], + 'lastname'=> $in["lastname"], + 'random_text' => $randomText + ]; + + $insert_id = $this->insert_db($inData, 'members_pending'); + if( $insert_id>=0){ // for now + $sqlQ = "SELECT id AS insert_id,uuid FROM members_pending WHERE username='".$in["username"]."' AND random_text='$randomText' AND password='$passEnr' LIMIT 1"; + $query = $this->db->query($sqlQ); + $dat = $query->getResultArray(); + $insert_id = $dat[0]['insert_id']; + $uuid = $dat[0]['uuid']; + $status=1; + } + return $inx = [ + 'insert_id' => $insert_id, + 'uuid' => $uuid, + 'status' => $status, + 'error_msg' => '', + 'raw_data' => $in, + ]; + + } + + private function encryptmd5($rwStstr){ + + $sqlQ = "SELECT md5('$rwStstr') AS md5_string"; + log_message('critical', "encryptmd5-Entered".$sqlQ ); + $query = $this->db->query($sqlQ); + $data = $query->getResultArray(); + return $data[0]['md5_string']; + } + + public function tempCodes(){ + $sqlQ = "SELECT id AS insert_id,uuid,username,random_text FROM members_pending ORDER BY id DESC LIMIT 10"; + $query = $this->db->query($sqlQ); + return $query->getResultArray(); + } + +} + +/* +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);*/ diff --git a/app/Models/usersResetPass.php b/app/Models/usersResetPass.php new file mode 100644 index 0000000..918f39c --- /dev/null +++ b/app/Models/usersResetPass.php @@ -0,0 +1,133 @@ + $raw_array['email'], + 'status' => 1, + ]; + CREATE TABLE members_pending ( + id SERIAL, + uuid UUID DEFAULT (gen_random_uuid()), + username VARCHAR(50) NOT NULL, + firstname VARCHAR(50), + lastname VARCHAR(50), + email VARCHAR(50), + password VARCHAR(100) NOT NULL, + random_text VARCHAR(15), + status INT DEFAULT 0, + updated timestamp without time zone DEFAULT now(), + added timestamp without time zone DEFAULT now() + ); +*/ + public function startPassReset($in) + { + $insert_id=0; + $uuid=''; + $status=0; + $passEnr = '';// $this->encryptmd5($in["password"]); + $randomText = rand(1010101,999999);// rand(1010101,999999); + $pdata =[]; + + $sqlQ = "SELECT id AS member_id,uuid FROM members WHERE username='".$in["username"]."' "; + $query = $this->db->query($sqlQ); + $data['user_data'] = $query->getResultArray(); + + if (count($data['user_data']) == 1) { + $userData = $data['user_data'][0]; + $pdata = [ + 'username'=> $in["username"], + 'member_uid'=> $userData["uuid"], + 'random_text' => $randomText, + 'status'=>1 + ]; + + $insert_id = $this->insert_db($pdata, 'members_password_reset'); + if( $insert_id>=0){ // for now + + } + } + + +/* + CREATE TABLE members_password_reset ( + id SERIAL, + uuid UUID DEFAULT (gen_random_uuid()), + username VARCHAR(50) NOT NULL, + member_uid VARCHAR(50), + random_text VARCHAR(15), + status INT DEFAULT 0, + updated timestamp without time zone DEFAULT now(), + added timestamp without time zone DEFAULT now() + ); + + $inData =[ + 'username'=> $in["username"], + 'email'=> $in["email"], + 'password'=> $passEnr, + 'firstname'=> $in["firstname"], + 'lastname'=> $in["lastname"], + 'random_text' => $randomText + ]; + + $insert_id = $this->insert_db($inData, 'members_pending'); + if( $insert_id>=0){ // for now + $sqlQ = "SELECT id AS insert_id,uuid FROM members WHERE username='".$in["username"]."' AND random_text='$randomText' AND password='$passEnr' LIMIT 1"; + $query = $this->db->query($sqlQ); + $dat = $query->getResultArray(); + $insert_id = $dat[0]['insert_id']; + $uuid = $dat[0]['uuid']; + $status=1; + } + */ + + return $inx = [ + 'insert_id' => $insert_id, + 'uuid' => $uuid, + 'status' => $status, + 'pdata' => $pdata, + 'error_msg' => '', + 'raw_data' => $in, + ]; + + } + + public function tempCodes(){ + $sqlQ = "SELECT username,uuid,member_uid,random_text FROM members_password_reset WHERE status = 1 ORDER BY id DESC LIMIT 10"; + $query = $this->db->query($sqlQ); + return $query->getResultArray(); + } + + private function encryptmd5($rwStstr){ + + $sqlQ = "SELECT md5('$rwStstr') AS md5_string"; + log_message('critical', "encryptmd5-Entered".$sqlQ ); + $query = $this->db->query($sqlQ); + $data = $query->getResultArray(); + return $data[0]['md5_string']; + } + + + +} + +/* +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);*/ diff --git a/sample_env b/sample_env new file mode 100644 index 0000000..7e11675 --- /dev/null +++ b/sample_env @@ -0,0 +1,145 @@ +#-------------------------------------------------------------------- +# Example Environment Configuration file +# +# This file can be used as a starting point for your own +# custom .env files, and contains most of the possible settings +# available in a default install. +# +# By default, all of the settings are commented out. If you want +# to override the setting, you must un-comment it by removing the '#' +# at the beginning of the line. +#-------------------------------------------------------------------- + + +#-------------------------------------------------------------------- +# ENVIRONMENT +#-------------------------------------------------------------------- + +# CI_ENVIRONMENT = production +UID=1000 +MYSQL_ROOT_PASSWORD=cod31gn1t3 +MYSQL_DATABASE=codeigniter_db +CI_ENVIRONMENT=production + + +MYFIT_DATABASE_HOSTNAME='10.20.30.60' +MYFIT_DATABASE_USERNAME='myfit' +MYFIT_DATABASE_PASSWORD='myfit' +MYFIT_DATABASE='myfit_dev' + + +#-------------------------------------------------------------------- +# APP +#-------------------------------------------------------------------- + +# app.baseURL = '' +# app.forceGlobalSecureRequests = false + +# app.sessionDriver = 'CodeIgniter\Session\Handlers\FileHandler' +# app.sessionCookieName = 'ci_session' +# app.sessionExpiration = 7200 +# app.sessionSavePath = null +# app.sessionMatchIP = false +# app.sessionTimeToUpdate = 300 +# app.sessionRegenerateDestroy = false + +# app.CSPEnabled = false + +#-------------------------------------------------------------------- +# DATABASE +#-------------------------------------------------------------------- + +# database.default.hostname = localhost +# database.default.database = ci4 +# database.default.username = root +# database.default.password = root +# database.default.DBDriver = MySQLi +# database.default.DBPrefix = + +# database.tests.hostname = localhost +# database.tests.database = ci4 +# database.tests.username = root +# database.tests.password = root +# database.tests.DBDriver = MySQLi +# database.tests.DBPrefix = + +#-------------------------------------------------------------------- +# CONTENT SECURITY POLICY +#-------------------------------------------------------------------- + +# contentsecuritypolicy.reportOnly = false +# contentsecuritypolicy.defaultSrc = 'none' +# contentsecuritypolicy.scriptSrc = 'self' +# contentsecuritypolicy.styleSrc = 'self' +# contentsecuritypolicy.imageSrc = 'self' +# contentsecuritypolicy.base_uri = null +# contentsecuritypolicy.childSrc = null +# contentsecuritypolicy.connectSrc = 'self' +# contentsecuritypolicy.fontSrc = null +# contentsecuritypolicy.formAction = null +# contentsecuritypolicy.frameAncestors = null +# contentsecuritypolicy.frameSrc = null +# contentsecuritypolicy.mediaSrc = null +# contentsecuritypolicy.objectSrc = null +# contentsecuritypolicy.pluginTypes = null +# contentsecuritypolicy.reportURI = null +# contentsecuritypolicy.sandbox = false +# contentsecuritypolicy.upgradeInsecureRequests = false + +#-------------------------------------------------------------------- +# COOKIE +#-------------------------------------------------------------------- + +# cookie.prefix = '' +# cookie.expires = 0 +# cookie.path = '/' +# cookie.domain = '' +# cookie.secure = false +# cookie.httponly = false +# cookie.samesite = 'Lax' +# cookie.raw = false + +#-------------------------------------------------------------------- +# ENCRYPTION +#-------------------------------------------------------------------- + +# encryption.key = +# encryption.driver = OpenSSL +# encryption.blockSize = 16 +# encryption.digest = SHA512 + +#-------------------------------------------------------------------- +# HONEYPOT +#-------------------------------------------------------------------- + +# honeypot.hidden = 'true' +# honeypot.label = 'Fill This Field' +# honeypot.name = 'honeypot' +# honeypot.template = '' +# honeypot.container = '
{template}
' + +#-------------------------------------------------------------------- +# SECURITY +#-------------------------------------------------------------------- + +# security.csrfProtection = 'cookie' +# security.tokenRandomize = false +# security.tokenName = 'csrf_token_name' +# security.headerName = 'X-CSRF-TOKEN' +# security.cookieName = 'csrf_cookie_name' +# security.expires = 7200 +# security.regenerate = true +# security.redirect = true +# security.samesite = 'Lax' + +#-------------------------------------------------------------------- +# LOGGER +#-------------------------------------------------------------------- + +# logger.threshold = 4 + +#-------------------------------------------------------------------- +# CURLRequest +#-------------------------------------------------------------------- + +# curlrequest.shareOptions = true