Add insert for contacts

This commit is contained in:
2023-01-22 17:42:51 -05:00
parent 3bd5ea445a
commit 53529c2df7
3 changed files with 101 additions and 42 deletions
+18
View File
@@ -7,9 +7,27 @@ CREATE DATABASE site_mermsemr_com;
CREATE USER 'mermsemr'@'192.168.%' IDENTIFIED BY 'may12002'; CREATE USER 'mermsemr'@'192.168.%' IDENTIFIED BY 'may12002';
GRANT ALL PRIVILEGES ON site_mermsemr_com.* TO 'mermsemr'@'192.168.%'; GRANT ALL PRIVILEGES ON site_mermsemr_com.* TO 'mermsemr'@'192.168.%';
CREATE USER 'mermsemr'@'10.%' IDENTIFIED BY 'may12002';
GRANT ALL PRIVILEGES ON site_mermsemr_com.* TO 'mermsemr'@'10.%';
FLUSH PRIVILEGES;
https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql
SELECT User, Host, plugin FROM mysql.user; SELECT User, Host, plugin FROM mysql.user;
CREATE TABLE `site_mermsemr_com`.`myfit_contact` (
`uuid` VARCHAR(32) DEFAULT (uuid()),
`id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(45) NULL,
`email` VARCHAR(45) NULL,
`country` VARCHAR(2) NULL,
`phone` VARCHAR(15) NULL,
`message` TEXT NULL,
`added` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE INDEX `idmyfit_contact_UNIQUE` (`id` ASC) VISIBLE);
+78 -40
View File
@@ -1,10 +1,10 @@
<?php <?php
namespace App\Controllers; namespace App\Controllers;
use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\API\ResponseTrait; use CodeIgniter\API\ResponseTrait;
//use CodeIgniter\Database\RawSql;
class Myfit extends BaseController class Myfit extends BaseController
{ {
@@ -16,7 +16,6 @@ class Myfit extends BaseController
$this->request = $request = \Config\Services::request(); $this->request = $request = \Config\Services::request();
} }
public function index() public function index()
{ {
$mBlogData = new \App\Models\myfitBlogData(); $mBlogData = new \App\Models\myfitBlogData();
@@ -35,32 +34,70 @@ class Myfit extends BaseController
); );
$something = $this->request->getVar('name'); $something = $this->request->getVar('name');
*/ */
header("Access-Control-Allow-Origin: * "); header('Access-Control-Allow-Origin: * ');
//header("Access-Control-Allow-Origin: http://localhost:9057 "); //header("Access-Control-Allow-Origin: http://localhost:9057 ");
header("Access-Control-Expose-Headers: Access-Control-Allow-Origin"); header('Access-Control-Expose-Headers: Access-Control-Allow-Origin');
header("Access-Control-Allow-Credentials: true "); 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-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'); header('Content-type: application/json');
$startInsert = false;
$raw_json = file_get_contents("php://input"); $status = 0;
$message_id = '';
$raw_json = file_get_contents('php://input');
$raw_array = json_decode($raw_json, true); $raw_array = json_decode($raw_json, true);
$something = $raw_array["name"]; $something = $raw_array['name'];
$db = \Config\Database::connect('mermsemr_site');
if (
$raw_array['country'] != '' &&
$raw_array['email'] != '' &&
$raw_array['name'] != '' &&
$raw_array['message'] != '' &&
$raw_array['phone'] != ''
) {
$startInsert = true;
}
else{
$status = -2;
$message_id = 'Parameters not recieved';
}
$data = [
'country' => $raw_array['country'],
'email' => $raw_array['email'],
'name' => $raw_array['name'],
'message' => $raw_array['message'],
'phone' => $raw_array['phone'],
];
if ($startInsert) {
try {
$db->table('myfit_contact')->insert($data);
// $insert_id = $db->affectedRows();
$insert_id = $db->insertId();
$query = $db->query(
'SELECT uuid, id FROM myfit_contact WHERE id = ' .
$insert_id
);
$row = $query->getRow();
$message_id = $row->uuid;
$status = $row->id;
} catch (Exception $e) {
$status = -1;
$message_id = '';
}
}
$inx = [ $inx = [
'message_id' => rand(100, 8888) . 'gsgsgsgsg-sssfsgggsgs-ususususu', 'message_id' => $message_id,
'status'=>1 'status' => $status,
]; ];
$mBlogData = new \App\Models\myfitBlogData();
$res1 = $mBlogData->getBlogData([]);
//return $this->response->setJson($res1);
return $this->response->setJson($inx); return $this->response->setJson($inx);
} }
public function blogdata() public function blogdata()
{ {
/* header("Access-Control-Allow-Origin: *"); /* header("Access-Control-Allow-Origin: *");
//header("x-devicetoken : *"); //header("x-devicetoken : *");
//header("Authorization : Token"); //header("Authorization : Token");
header("Access-Control-Expose-Headers: Access-Control-Allow-Origin"); header("Access-Control-Expose-Headers: Access-Control-Allow-Origin");
@@ -73,28 +110,28 @@ class Myfit extends BaseController
header2 = ('Access-Control-Allow-Origin', 'https://serviceview.example.com') 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-Allow-Origin: http://localhost:9057 ");
header("Access-Control-Expose-Headers: Access-Control-Allow-Origin"); header('Access-Control-Expose-Headers: Access-Control-Allow-Origin');
header("Access-Control-Allow-Credentials: true "); 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-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'); header('Content-type: application/json');
$mBlogData = new \App\Models\myfitBlogData(); $mBlogData = new \App\Models\myfitBlogData();
$res1 = $mBlogData->getBlogData([]); $res1 = $mBlogData->getBlogData([]);
return $this->response->setJson($res1); return $this->response->setJson($res1);
// $this->setGetReturn(res1); // $this->setGetReturn(res1);
} }
public function country() public function country()
{ {
//header("Access-Control-Allow-Origin: http://localhost:9057 "); //header("Access-Control-Allow-Origin: http://localhost:9057 ");
header("Access-Control-Allow-Origin: * "); header('Access-Control-Allow-Origin: * ');
header("Access-Control-Expose-Headers: Access-Control-Allow-Origin"); header('Access-Control-Expose-Headers: Access-Control-Allow-Origin');
header("Access-Control-Allow-Credentials: true "); 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-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'); header('Content-type: application/json');
$mCountry = new \App\Models\myfitCountry(); $mCountry = new \App\Models\myfitCountry();
@@ -104,39 +141,40 @@ class Myfit extends BaseController
public function faq() public function faq()
{ {
//header("Access-Control-Allow-Origin: http://localhost:9057 "); //header("Access-Control-Allow-Origin: http://localhost:9057 ");
header("Access-Control-Allow-Origin: * "); header('Access-Control-Allow-Origin: * ');
header("Access-Control-Expose-Headers: Access-Control-Allow-Origin"); header('Access-Control-Expose-Headers: Access-Control-Allow-Origin');
header("Access-Control-Allow-Credentials: true "); 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-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'); header('Content-type: application/json');
$mFaq = new \App\Models\myfitFaqData(); $mFaq = new \App\Models\myfitFaqData();
return $this->response->setJson($mFaq->getSiteFaq([])); return $this->response->setJson($mFaq->getSiteFaq([]));
} }
public function pricing() public function pricing()
{ {
//header("Access-Control-Allow-Origin: http://localhost:9057 "); //header("Access-Control-Allow-Origin: http://localhost:9057 ");
header("Access-Control-Allow-Origin: * "); header('Access-Control-Allow-Origin: * ');
header("Access-Control-Expose-Headers: Access-Control-Allow-Origin"); header('Access-Control-Expose-Headers: Access-Control-Allow-Origin');
header("Access-Control-Allow-Credentials: true "); 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-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'); header('Content-type: application/json');
$mPricing = new \App\Models\myfitPricing(); $mPricing = new \App\Models\myfitPricing();
return $this->response->setJson($mPricing->getSitePricing([])); return $this->response->setJson($mPricing->getSitePricing([]));
} }
private function setGetReturn($resp){ private function setGetReturn($resp)
header("Access-Control-Allow-Origin: * "); {
header('Access-Control-Allow-Origin: * ');
//header("Access-Control-Allow-Origin: http://localhost:9057 "); //header("Access-Control-Allow-Origin: http://localhost:9057 ");
header("Access-Control-Expose-Headers: Access-Control-Allow-Origin"); header('Access-Control-Expose-Headers: Access-Control-Allow-Origin');
header("Access-Control-Allow-Credentials: true "); 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-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'); header('Content-type: application/json');
return $this->response->setJson($resp); return $this->response->setJson($resp);
} }
} }
+5 -2
View File
@@ -12,7 +12,8 @@
"ext-mbstring": "*", "ext-mbstring": "*",
"kint-php/kint": "^4.0", "kint-php/kint": "^4.0",
"laminas/laminas-escaper": "^2.9", "laminas/laminas-escaper": "^2.9",
"psr/log": "^1.1" "psr/log": "^1.1",
"guzzlehttp/guzzle": "^7.3"
}, },
"require-dev": { "require-dev": {
"codeigniter/coding-standard": "^1.1", "codeigniter/coding-standard": "^1.1",
@@ -41,7 +42,9 @@
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"CodeIgniter\\": "system/" "CodeIgniter\\": "system/",
"App\\": "app",
"Config\\": "app/Config"
}, },
"exclude-from-classmap": [ "exclude-from-classmap": [
"**/Database/Migrations/**" "**/Database/Migrations/**"