public function generate(Request $request) { $data = $request->all(); $validator = Validator::make($data, ['token' => 'required', 'number' => 'required']); if ($validator->fails()) { return validatorError($validator->errors()); } $token = $this->getToken($data['token']); if (!$token->owner->hasApiEnabled($this->api)) { return errorResponse('api_disabled', 403); } if ($token == null) { return errorResponse("token_invalid", 403); } if (!$token->enabled) { return errorResponse("token_disabled", 403); } if (!$token->validDayLimit()) { return errorResponse('day_limit_reached', 403); } if (!$token->validMonthLimit()) { return errorResponse('month_limit_reached', 403); } $verification = Verification::create(['phone_number' => $data['number'], 'code' => $this->incrementalHash($this->api->configuration->token_length), 'expiration' => Carbon::now()->addMinutes($this->api->configuration->expiration)]); $sms = $this->api->configuration->message_content; $sms = str_replace("\\(code)", $verification->code, $sms); $this->sendApiRequest($data['number'], $sms, $token->owner->id); return successResponse('sent'); }
function validateNotEmpty($string) { if (empty(trim($string))) { errorResponse(); return false; } return true; }
/** * Pulls posted values for all fields in $fields_req array. * If a required field does not have a value, an error response is given. * * @param [Array] $fields_req a map of field name to required */ function setMessageBody($fields_req) { $message_body = ""; foreach ($fields_req as $name => $required) { if ($required && empty($name)) { errorResponse("{$name} is empty."); } else { $message_body .= ucfirst($name) . ": " . $_POST[$name] . "\n"; } } return $message_body; }
/** * Pulls posted values for all fields in $fields_req array. * If a required field does not have a value, an error response is given. */ function constructMessageBody() { $fields_req = array("name" => true, "email" => true, "message" => true); $message_body = ""; foreach ($fields_req as $name => $required) { $postedValue = $_POST[$name]; if ($required && empty($postedValue)) { errorResponse("{$name} is empty."); } else { $message_body .= ucfirst($name) . ": " . $postedValue . "\n"; } } return $message_body; }
if (isset($_GET['current'])) { $tripId = Trip::findCurrentTrip(); if (!$tripId) { $tripId = ''; } } else { if (isset($_GET['tripId'])) { $tripId = $_GET['tripId']; } } if ($tripId === '') { $response = errorResponse(RESPONSE_BAD_REQUEST); } else { $object = new Trip($tripId); if ($object->getCreated() === null) { $response = errorResponse(RESPONSE_NOT_FOUND); } else { $response = successResponse(); $response['tripId'] = $object->getTripId(); $response['created'] = $object->getCreated(); $response['updated'] = $object->getUpdated(); $response['name'] = $object->getName(); $response['description'] = $object->getDescription(); $response['bannerImg'] = $object->getBannerImg(); $response['startDate'] = $object->getStartDate(); $response['endDate'] = $object->getEndDate(); $response['active'] = $object->getActive(); $response['deleted'] = $object->getDeleted(); // Do NOT return the hash field on the GET service. $journal = Journal::getFirstJournal($object->getTripId()); if ($journal !== null) {
if (isset($data['password'])) { $password = $data['password']; } if ($userId === '' || $password === '') { $response = errorResponse(RESPONSE_BAD_REQUEST); } else { $user = new User($userId); if ($user->getCreated() === null) { $response = errorResponse(RESPONSE_NOT_FOUND); } else { if ($user->checkPassword($password)) { // password matches, need to allow for hash update (if hash // algorithm changed, the new hash can only be stored in the // database when we have the actual password, and only at login // time do we have the actual password) $user->updatePasswordHash($password); $authId = Auth::generateAuthId(); $auth = new Auth($authId); $auth->setUserId($userId); $auth->save(); $response = successResponse(); $response['authId'] = $authId; } else { $response = errorResponse(RESPONSE_UNAUTHORIZED); } } } } else { $response = errorResponse(RESPONSE_METHOD_NOT_ALLOWED, $_SERVER['REQUEST_METHOD']); } echo json_encode($response);
exit; } $email = Configuration::get($prefix . 'EMAIL'); $token = Configuration::get($prefix . 'TOKEN'); $cancellation = new Cancellation($email, $token); $cancellation->enableSandBox(Configuration::get($prefix . 'SANDBOX')); try { $response = $cancellation->execute($id_transacao); if ($response->transactionStatusId == 7 || $response->transactionStatusId == 6) { updateOrder($id_pedido, $response); writeHistory($id_pedido, $response); } } catch (ValidationException $e) { die(errorResponse($e)); } catch (ConnectionException $e) { die(errorResponse($e)); } echo json_encode($response); exit; function errorResponse($e) { $erros = $e->getErrors(); if (!empty($erros)) { return $e->getErrors()->list[0]->description; } } function updateOrder($orderId, $response) { $order_state_id = (int) Configuration::get('PS_OS_BCASH_CANCELLED'); if ($response->transactionStatusId == 6) { $order_state_id = (int) Configuration::get('PS_OS_BCASH_REFUNDED');
$object->setAccess($data['access']); } if (isset($data['email'])) { $object->setEmail($data['email']); } if (isset($data['notification'])) { $object->setNotification($data['notification']); } if (isset($data['tempCode'])) { $object->setTempCode($data['tempCode']); } if (isset($data['deleted'])) { $object->setDeleted($data['deleted']); } if (isset($data['hash'])) { $object->setHash($data['hash']); } if ($object->save()) { $response = successResponse(); } else { $response = errorResponse(RESPONSE_INTERNAL_ERROR); } } else { $response = errorResponse(RESPONSE_BAD_REQUEST, 'Need user ID'); } } else { $response = errorResponse(RESPONSE_METHOD_NOT_ALLOWED); } } } echo json_encode($response);
$name = $data['name']; $object = new TripAttribute($tripId, $name); if (isset($data['created'])) { $object->setCreated($data['created']); } if (isset($data['updated'])) { $object->setUpdated($data['updated']); } if (isset($data['value'])) { $object->setValue($data['value']); } if (isset($data['deleted'])) { $object->setDeleted($data['deleted']); } if (isset($data['hash'])) { $object->setHash($data['hash']); } if ($object->save()) { $response = successResponse(); } else { $response = errorResponse(RESPONSE_INTERNAL_ERROR); } } else { $response = errorResponse(RESPONSE_BAD_REQUEST); } } else { $response = errorResponse(RESPONSE_BAD_REQUEST); } } } echo json_encode($response);
$object->setUserId($data['userId']); } if (isset($data['journalDate'])) { $object->setJournalDate($data['journalDate']); } if (isset($data['journalTitle'])) { $object->setJournalTitle($data['journalTitle']); } if (isset($data['journalText'])) { $object->setJournalText($data['journalText']); } if (isset($data['deleted'])) { $object->setDeleted($data['deleted']); } if (isset($data['hash'])) { $object->setHash($data['hash']); } if ($object->save()) { $response = successResponse(); } else { $response = errorResponse(RESPONSE_INTERNAL_ERROR); } } else { $response = errorResponse(RESPONSE_BAD_REQUEST, 'tripId or journalId not set'); } } else { $response = errorResponse(RESPONSE_BAD_REQUEST, 'not GET or PUT response'); } } } echo json_encode($response);
} $step_array['step_progress'] = $step_progress_array; } } array_push($steps_array, $step_array); } $task_array['steps'] = $steps_array; array_push($tasks_array, $task_array); } $response_array = array("status" => "ok", "module_id" => $module_id, "tasks" => $tasks_array); $response = json_encode($response_array); } else { $response = errorResponse("The module id provided is not valid"); } } else { $response = errorResponse("module_id is expected"); } } echo $response; function taskByModuleId($module_id) { return getTaskByModuleId($module_id); } function getTaskByModuleId($module_id) { $sql = sprintf("SELECT t.task_id, name, brief_desc, t.desc, thumb_url FROM task t JOIN module_task mt ON t.task_id = mt.task_id WHERE module_id = %d", $module_id); return executeSql($sql); } function taskProgressByTaskIdUserId($task_id, $user_id) { return getTaskProgressByTaskIdUserId($task_id, $user_id);
$module_id = isset($module_id) ? $module_id : $_GET['module_id']; $show_all_for_user = isset($show_all_for_user) ? $show_all_for_user : $_GET['show_all_for_user']; $new_module = isset($new_module) ? $new_module : $_POST['new_module']; $response = ""; if ($user_id && !$show_all_for_user) { if (checkId($user_id)) { $response = moduleByUserId($user_id); } else { $response = errorResponse("The user id provided is not valid"); } } else { if ($module_id) { if (checkId($module_id)) { $response = moduleByModuleId($module_id); } else { $response = errorResponse("The module id provided is not valid"); } } else { if ($new_module) { $user_id = intval($_POST['user_id']); $module_id = intval($_POST['module_id']); $progress = checkString($_POST['progress']); $is_complete = checkString($_POST['is_complete']); $date_completed = checkString($_POST['date_completed']); if (checkId($user_id) && checkId($module_id)) { $response = moduleUserProgress($user_id, $module_id, $progress, $is_complete, $date_completed); } } else { $response = allModules($user_id); } }
$object->setUserId($data['userId']); } if (isset($data['referenceId'])) { $object->setReferenceId($data['referenceId']); } if (isset($data['commentText'])) { $object->setCommentText($data['commentText']); } if (isset($data['deleted'])) { $object->setDeleted($data['deleted']); } if (isset($data['hash'])) { $object->setHash($data['hash']); } if ($object->save()) { $response = successResponse(); } else { // @codeCoverageIgnoreStart // cannot unit test database errors $response = errorResponse(RESPONSE_INTERNAL_ERROR); // @codeCoverageIgnoreEnd } } else { $response = errorResponse(RESPONSE_BAD_REQUEST); } } else { $response = errorResponse(RESPONSE_METHOD_NOT_ALLOWED, 'must be get or put'); } } } echo json_encode($response);
<?php include_once "connect.php"; include_once "common.php"; $user_id = isset($user_id) ? $user_id : $_GET['user_id']; $response = ""; if ($user_id) { if (checkId($user_id)) { $response = userById($user_id); } else { $response = errorResponse("The user id provided is not valid"); } } else { $response = errorResponse("The user id was not provided"); } echo $response; function userById($user_id) { $result = getUserById($user_id); return formJson($result); } function getUserById($user_id) { $sql = sprintf("SELECT user_id, first_name, last_name, age, email, receive_notifications, is_new, lang_id FROM user WHERE user_id = '%d'", $user_id); return executeSql($sql); } function formJson($result) { $users = array(); while ($item = mysql_fetch_array($result)) { $user = array("user_id" => $item['user_id'], "first_name" => $item['first_name'], "last_name" => $item['last_name'], "age" => $item['age'], "email" => $item['email'], "receive_notifications" => $item['receive_notifications'], "is_new" => $item['is_new'], "lang_id" => $item['lang_id']);
public function sendSmsTemplate(Request $request) { $data = $request->all(); $validator = Validator::make($data, ['token' => 'required', 'template' => 'required', 'number' => 'required']); if ($validator->fails()) { return validatorError($validator->errors()); } $token = $this->getToken($data['token']); if ($token == null) { return errorResponse("token_invalid", 403); } if (!$token->enabled) { return errorResponse("token_disabled", 403); } if (!$token->validDayLimit()) { return errorResponse('day_limit_reached', 403); } if (!$token->validMonthLimit()) { return errorResponse('month_limit_reached', 403); } $template = SmsTemplate::where('sms_id', $data['template'])->first(); if ($template == null) { return errorResponse('template_not_found', 404); } $forFill = $data; unset($forFill['token']); unset($forFill['template']); $template->fillData($forFill); $this->sendApiRequest($data['number'], $template->getFilled(), $token->owner->id); return successResponse('sent'); }
$object->setExternalType($data['externalType']); } if (isset($data['externalId'])) { $object->setExternalId($data['externalId']); } if (isset($data['access'])) { $object->setAccess($data['access']); } if (isset($data['email'])) { $object->setEmail($data['email']); } if (isset($data['notification'])) { $object->setNotification($data['notification']); } if (isset($data['tempCode'])) { $object->setTempCode($data['tempCode']); } if (isset($data['deleted'])) { $object->setDeleted($data['deleted']); } if ($object->save()) { $response = successResponse(); } else { $response = errorResponse(RESPONSE_INTERNAL_ERROR); } } } } else { $response = errorResponse(RESPONSE_METHOD_NOT_ALLOWED, 'Use Put method'); } echo json_encode($response);
} else { if (!$auth->canPutComment($tripId, $commentId)) { $response = errorResponse(RESPONSE_UNAUTHORIZED); } else { $object = new Comment($tripId, $commentId); if (isset($data['userId'])) { $object->setUserId($data['userId']); } if (isset($data['referenceId'])) { $object->setReferenceId($data['referenceId']); } if (isset($data['commentText'])) { $object->setCommentText($data['commentText']); } if (isset($data['deleted'])) { $object->setDeleted($data['deleted']); } if ($object->save()) { $response = successResponse(); } else { // @codeCoverageIgnoreStart // cannot unit test database errors $response = errorResponse(RESPONSE_INTERNAL_ERROR); // @codeCoverageIgnoreEnd } } } } else { $response = errorResponse(RESPONSE_METHOD_NOT_ALLOWED, 'Must use PUT method'); } echo json_encode($response);
$result = errorResponse("Incorrect article identifier"); die($result); } // try to load the blog info too, as we are going to need it $blogs = new Blogs(); $blogInfo = $blogs->getBlogInfo($article->getBlog()); // a bit of protection... if (!$blogInfo) { trackbackLog("ERROR: Article id " . $article->getId() . " points to blog " . $article->getBlog() . " that doesn't exist!"); $result = errorResponse("The blog does not exist"); die($result); } // if the blog is disabled, then we shoulnd't take trackbacks... if ($blogInfo->getStatus() != BLOG_STATUS_ACTIVE) { trackbackLog("ERROR: The blog " . $blogInfo->getBlog() . " is set as disabled and cannot receive trackbacks!"); $result = errorResponse("The blog is not active"); die($result); } // if everything went fine, load the plugins so that we can throw some events... $pm =& PluginManager::getPluginManager(); $pm->loadPlugins(); // and also configure the BlogInfo and UserInfo objects so that they know // who threw the events... $pm->setBlogInfo($blogInfo); $userInfo = $blogInfo->getOwnerInfo(); $pm->setUserInfo($userInfo); // receives the request and adds it to the database $trackbacks = new TrackBacks(); // create teh trackback object $now = new Timestamp(); $trackback = new Trackback($url, $title, $articleId, $excerpt, $blogName, $now->getTimestamp());
* Comment: <message/comment submitted by user> * * @param String $name name of submitter * @param String $message message/comment submitted */ function setMessageBody($name, $message) { $message_body = "Name: " . $name . "\n\n"; $message_body .= "Comment:\n" . nl2br($message); return $message_body; } $email = $_POST['email']; $message = $_POST['message']; header('Content-type: application/json'); //do some simple validation. this should have been validated on the client-side also if (empty($email) || empty($message)) { errorResponse('Email or message is empty.'); } //do Captcha check, make sure the submitter is not a robot:)... include_once './vender/securimage/securimage.php'; $securimage = new Securimage(); if (!$securimage->check($_POST['captcha_code'])) { errorResponse('Invalid Security Code'); } //try to send the message if (mail(MY_EMAIL, "Newspective Contact", setMessageBody($_POST["name"], $message), "From: {$email}")) { echo json_encode(array('message' => 'Your message was successfully submitted.')); } else { header('HTTP/1.1 500 Internal Server Error'); echo json_encode(array('message' => 'Unexpected error while attempting to send e-mail.')); }
$object = new Media($tripId, $mediaId); if (isset($data['type'])) { $object->setType($data['type']); } if (isset($data['caption'])) { $object->setCaption($data['caption']); } if (isset($data['timestamp'])) { $object->setTimestamp($data['timestamp']); } if (isset($data['location'])) { $object->setLocation($data['location']); } if (isset($data['width'])) { $object->setWidth($data['width']); } if (isset($data['height'])) { $object->setHeight($data['height']); } if (isset($data['deleted'])) { $object->setDeleted($data['deleted']); } if ($object->save()) { $response = successResponse(); } else { $response = errorResponse(RESPONSE_INTERNAL_ERROR); } } } } echo json_encode($response);
<Error Time="{$error_time}" Id="{$error_time_id}"> <ErrorCode>{$code}</ErrorCode> <Message>{$message}</Message> <DebugData>{$debugdata}</DebugData> </Error> </Response> </Autodiscover> ERROR; $request->DoResponse($code, $response, 'text/xml; charset="utf-8"'); exit(0); // unneccessary } if (!isset($request->xml_tags)) { errorResponse(406, translate("Body contains no XML data!")); } $position = 0; $xmltree = BuildXMLTree($request->xml_tags, $position); if (!is_object($xmltree)) { errorResponse(406, translate("REPORT body is not valid XML data!")); } $user_email = $xmltree->GetPath('/' . $ns_outlook_req_2006 . ':Autodiscover' . '/' . $ns_outlook_req_2006 . ':Request' . '/' . $ns_outlook_req_2006 . ':EMailAddress'); if (count($user_email) < 1) { errorResponse(500, "User not found."); } $user_email = $user_email[0]->GetContent(); $principal = new Principal(); $reply = new XMLDocument(array($ns_outlook_resp_2006a => "")); $response = array(new XMLElement('User', array(new XMLElement('DisplayName', $principal->{$fullname}), new XMLElement('AutoDiscoverSMTPAddress', $user_email)))); $response[] = new XMLElement('Account', array(new XMLElement('AccountType', 'email'), new XMLElement('Action', 'settings'), new XMLElement('Protocol', array(new XMLElement('Type', 'DAV'), new XMLElement('Server', $c->domain_name), new XMLElement('LoginName', $principal->username()))))); $autodiscover = new XMLElement("Autodiscover", $responses, $reply->GetXmlNsArray(), $ns_exchange_resp_2006); $request->XMLResponse(207, $autodiscover);