File read
This commit is contained in:
@@ -133,6 +133,9 @@ enum { PARTNER_STRIPE };
|
||||
#define WRENCHBOARD_USER_LOGOUT 301
|
||||
#define WRENCHBOARD_CREATE_ACCOUNT 320
|
||||
|
||||
|
||||
#define WRENCHBOARD_GET_MEDIA 650
|
||||
|
||||
// -- CRON JOBS
|
||||
#define WRB_JOB_CRONJOB 770
|
||||
#define WRB_CRONJOB_JOBDUE_REMINDER 771
|
||||
|
||||
@@ -32,55 +32,52 @@ CREATE TABLE members_myfiles (
|
||||
);
|
||||
ALTER TABLE ONLY members_myfiles
|
||||
ADD CONSTRAINT members_myfiles_id_key UNIQUE (id);
|
||||
|
||||
$data = [
|
||||
'action' => WRENCHBOARD_GET_MEDIA,
|
||||
'sessionid' => $sessionId,
|
||||
'file_section' => $fileSection,
|
||||
'file_uid' => $fileUID,
|
||||
];
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/* This profile apps*/
|
||||
long WrenchFindStoredMedia(CVars in, CVars &out) {
|
||||
logfmt(logINFO, "WrenchUpdateUserProfile()");
|
||||
logfmt(logINFO, "WrenchFindStoredMedia()");
|
||||
long ret = PHP_API_BAD_PARAM;
|
||||
char vname[500];
|
||||
try {
|
||||
REQ_STRING(in, "firstname", 3, 49, "(.*)");
|
||||
REQ_STRING(in, "lastname", 3, 49, "(.*)");
|
||||
REQ_STRING(in, "email", 5, 150, "(.*)");
|
||||
REQ_STRING(in, "state", 3, 150, "(.*)");
|
||||
REQ_STRING(in, "city", 3, 150, "(.*)");
|
||||
long member_id = REQ_LONG(in, "member_id", 1, -1);
|
||||
REQ_STRING(in, "uid", 3, 150, "(.*)");
|
||||
OPTIONAL(in, "online_name") REQ_STRING(in, "online_name", 3, 15, "(.*)");
|
||||
REQ_LONG(in, "pref_email", 1, -1);
|
||||
REQ_LONG(in, "pref_phone", 1, -1);
|
||||
REQ_STRING(in, "file_section", 5, 40, "(.*)");
|
||||
REQ_STRING(in, "sessionid", 3, 150, "(.*)");
|
||||
REQ_STRING(in, "file_uid", 3, 150, "(.*)");
|
||||
|
||||
const PGresult *res;
|
||||
res = pgsql_query("SELECT * FROM members WHERE id = %lu AND uid='%s'", member_id, in["uid"].c_str() );
|
||||
if (res != NULL && pgsql_num_rows(res) > 0) {
|
||||
CVars x;
|
||||
x["firstname"] = in["firstname"];
|
||||
x["firstname"].set_valid(true);
|
||||
x["lastname"] = in["lastname"];
|
||||
x["lastname"].set_valid(true);
|
||||
x["email"] = in["email"];
|
||||
x["email"].set_valid(true);
|
||||
x["state"] = in["state"];
|
||||
x["state"].set_valid(true);
|
||||
x["city"] = in["city"];
|
||||
x["city"].set_valid(true);
|
||||
switch(in["file_section"]){
|
||||
|
||||
x["online_name"] = in["online_name"];
|
||||
x["online_name"].set_valid(true);
|
||||
case "profile":
|
||||
snprintf(vname, sizeof (vname), "SELECT * FROM members WHERE id =1", in["file_uid"].c_str());
|
||||
break;
|
||||
|
||||
x["pref_email"] = in["pref_email"];
|
||||
x["pref_email"].set_valid(true);
|
||||
case "myfile":
|
||||
snprintf(vname, sizeof (vname), "SELECT * FROM members_myfiles WHERE uid ='%s'", in["file_uid"].c_str());
|
||||
break;
|
||||
|
||||
x["pref_phone"] = in["pref_phone"];
|
||||
x["pref_phone"].set_valid(true);
|
||||
case "contracts":
|
||||
snprintf(vname, sizeof (vname), "SELECT * FROM members WHERE id =1", in["file_uid"].c_str());
|
||||
break;
|
||||
|
||||
update_db_record(DBS_VALID, "members", x, member_id);
|
||||
case "family":
|
||||
snprintf(vname, sizeof (vname), "SELECT * FROM members WHERE id =1", in["file_uid"].c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
if ( load_db_record(out, "%s", vname) > 0){
|
||||
ret = PHP_API_OK;
|
||||
}
|
||||
|
||||
} catch (bad_parameter) {
|
||||
logfmt(logINFO, "ERROR CALL long WrenchUpdateUserProfile(CVars in, CVars &out)");
|
||||
logfmt(logINFO, "ERROR CALL long WrenchFindStoredMedia(CVars in, CVars &out)");
|
||||
}
|
||||
logfmt(logINFO, "/WrenchUpdateUserProfile()");
|
||||
logfmt(logINFO, "/WrenchFindStoredMedia()");
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -56,6 +56,10 @@ long wrenchboard_api_main(CVars in, CVars &out) {
|
||||
return SendSMSMessage(in, out);
|
||||
}
|
||||
|
||||
if( action == WRENCHBOARD_GET_MEDIA ){
|
||||
return WrenchFindStoredMedia(in, out);
|
||||
}
|
||||
|
||||
if (action == WRB_JOB_CRONJOB) {
|
||||
return sitecrons_calls(in, out);
|
||||
}
|
||||
|
||||
@@ -29,10 +29,9 @@ class WrenchMedia extends BaseController
|
||||
}
|
||||
|
||||
public function apigate(){
|
||||
|
||||
$call_backend = false;
|
||||
$uriSegments = explode("/", parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
|
||||
$segLen = count($uriSegments);
|
||||
echo $segLen;
|
||||
|
||||
if ( $segLen < 4 ){
|
||||
return;
|
||||
@@ -55,7 +54,7 @@ class WrenchMedia extends BaseController
|
||||
//We can check cache for the file or
|
||||
// OR
|
||||
// WE need to ask backend for this file now /
|
||||
|
||||
$call_backend = true;
|
||||
$data = [
|
||||
'action' => WRENCHBOARD_GET_MEDIA,
|
||||
'sessionid' => $sessionId,
|
||||
@@ -63,7 +62,12 @@ class WrenchMedia extends BaseController
|
||||
'file_uid' => $fileUID,
|
||||
];
|
||||
|
||||
|
||||
if ($data["action"] !=''){
|
||||
$wrenchboard = new \App\Models\BackendModel();
|
||||
$ret = $wrenchboard->wrenchboard_api($data, $out);
|
||||
$out['internal_return'] = $ret;
|
||||
}
|
||||
print_r($out);
|
||||
|
||||
$file = 'books.png';
|
||||
|
||||
@@ -81,93 +85,6 @@ class WrenchMedia extends BaseController
|
||||
|
||||
|
||||
}
|
||||
public function apigate33(){
|
||||
|
||||
log_message('critical', "Oauth-Gate");
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
log_message('critical', "0002");
|
||||
$call_backend = true;
|
||||
|
||||
header("Access-Control-Allow-Headers: Origin, X-API-KEY, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method, Access-Control-Allow-Headers, Authorization, observe, enctype, Content-Length, X-Csrf-Token");
|
||||
log_message('critical', "0003");
|
||||
header("Access-Control-Allow-Methods: GET, PUT, POST, DELETE, PATCH, OPTIONS");
|
||||
header("Access-Control-Allow-Credentials: true");
|
||||
header("Access-Control-Max-Age: 3600");
|
||||
header('content-type: application/json; charset=utf-8');
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
if ($method == "OPTIONS") {
|
||||
header("HTTP/1.1 200 OK CORS");
|
||||
log_message('critical', " apigate()-> OPTIONS DIE*****" );
|
||||
die();
|
||||
}
|
||||
|
||||
//$request = service('request');
|
||||
// what is the endpoint
|
||||
$uri = urldecode(current_url(true));
|
||||
$findme = '?';
|
||||
$pos = strpos($uri, $findme);
|
||||
if ($pos > 5) {
|
||||
$uri = substr($uri, 0, $pos);
|
||||
}
|
||||
log_message('critical', "API-GATE URI -> ".$uri );
|
||||
$pieces = explode('/', $uri);
|
||||
$psc = count($pieces);
|
||||
|
||||
$endpoint = $psc > 0 ? $pieces[$psc - 1] : '';
|
||||
log_message('critical', "Enpoint-> ".$endpoint );
|
||||
|
||||
$endpoints = $this->endPointList();
|
||||
$out = array();
|
||||
$res1 = [];
|
||||
if (array_key_exists($endpoint, $endpoints)) {
|
||||
} else {
|
||||
http_response_code(404);
|
||||
// tell the user product does not exist
|
||||
return json_encode([
|
||||
'message' => 'Endpoint not found.',
|
||||
'URI' => $uri,
|
||||
]);
|
||||
}
|
||||
|
||||
// echo "EXYTACT INPUT DATA HERE";
|
||||
$raw_json = file_get_contents('php://input');
|
||||
$raw_array = json_decode($raw_json, true);
|
||||
|
||||
$local_out =[];
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") { // if upload lets modify all the data
|
||||
if (isset($_FILES) && is_array($_FILES) && count($_FILES)>0) {
|
||||
$raw_array = array_merge($_POST,$_FILES);
|
||||
}
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
|
||||
log_message('critical', "Enpoint LOC2 HERE -> ".$endpoint );
|
||||
$get_param = $_GET['reqData'] ?? null;
|
||||
$raw_array = ($get_param!=null) ? json_decode($get_param, true):[];
|
||||
}
|
||||
//$in = $raw_array;
|
||||
log_message('critical', "wrenchboard_api-CALL RAW DATA".serialize($raw_array) );
|
||||
//-- move to another module start
|
||||
|
||||
|
||||
$in["loc"] = $_SERVER["REMOTE_ADDR"];
|
||||
// $in = $this->prepareOauthEndPointData($endpoint, $raw_array,$call_backend,$local_out);
|
||||
log_message('critical', "wrenchboard_api-CALL PREPARE DATA".serialize($in) );
|
||||
|
||||
|
||||
if ( $call_backend == true && $in["action"] !='' ){
|
||||
$wrenchboard = new \App\Models\BackendModel();
|
||||
$ret = $wrenchboard->wrenchboard_api($in, $out);
|
||||
$out['internal_return'] = $ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
$out = $local_out;
|
||||
}
|
||||
|
||||
//$this->doCacheStep($in, $out);
|
||||
return json_encode( ( new \App\Models\ResultFormatter() )->processOutJson($in, $out));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user