コード例 #1
1
ファイル: Response.php プロジェクト: glianyi/MyPHP
 public static function Json($json)
 {
     $response = new \Phalcon\Http\Response();
     $response->setJsonContent($json);
     $contentLength = strlen($response->getContent());
     $response->setHeader('ContentLength', $contentLength);
     $response->send();
     die;
 }
コード例 #2
1
ファイル: Acl.php プロジェクト: devsnippet/yona-cms
 private function resourceNotFound($resourceKey, View $view)
 {
     $view->setViewsDir(__DIR__ . '/../modules/Index/views/');
     $view->setPartialsDir('');
     $view->message = "Acl resource <b>{$resourceKey}</b> in <b>/app/config/acl.php</b> not exists";
     $view->partial('error/error404');
     $response = new \Phalcon\Http\Response();
     $response->setHeader(404, 'Not Found');
     $response->sendHeaders();
     echo $response->getContent();
     exit;
 }
コード例 #3
1
ファイル: Acl.php プロジェクト: phannguyenvn/test-git
 private function resourceNotFound($resource)
 {
     $this->view->setViewsDir(APP_URL . 'modules/site/views/');
     $this->view->setPartialsDir('');
     $this->view->message = "Acl resource <b>{$resource}</b> in <b>/app/config/acl.php</b> not exists";
     $this->view->partial('error/show404');
     $response = new \Phalcon\Http\Response();
     $response->setHeader(404, 'Not Found');
     $response->sendHeaders();
     echo $response->getContent();
     exit;
 }
コード例 #4
1
ファイル: CookieController.php プロジェクト: haneefadbg/demo
 public function getProductAction($categoryid)
 {
     $catid = intval($categoryid);
     if ($catid == 0) {
         $products = Product::find(array('order' => 'productid asc'));
     } else {
         $products = Product::find(array('conditions' => 'catid = ?0', 'bind' => array(0 => $catid), 'order' => 'productid asc'));
     }
     $response = new \Phalcon\Http\Response();
     $response->setHeader("Access-Control-Allow-Origin: *");
     $response->setHeader("Content-Type", "application/json");
     $response->setJsonContent($products->toArray());
     $this->view->disable();
     return $response;
 }
コード例 #5
1
 /**
  * Create a Response object with related parameters
  *
  * @param string $content
  * @param int $status
  * @param string $contentType
  * @param null $message
  * @return \Phalcon\Http\Response
  */
 protected function createResponse($content = self::NO_CONTENT, $status = self::STATUS_OK, $contentType = self::JSON, $message = null)
 {
     $response = new \Phalcon\Http\Response();
     // Allow CORS
     $response->setHeader(self::HEADER_ALLOW_ORIGIN, "*");
     // set new token to protected api
     if (!in_array($this->dispatcher->getActionName(), $this->publicAction) && !in_array($this->dispatcher->getActionName(), $this->authErrAction)) {
         $response->setHeader(self::HEADER_ACCESS_TOKEN, $this->session->get("loggedInUser")->access_token);
     }
     if ($message) {
         $response->setStatusCode($status, $message);
     } else {
         $response->setStatusCode($status, self::$MESSAGES[$status]);
     }
     if ($content !== self::NO_CONTENT) {
         $response->setHeader(self::HEADER_CONTENT_TYPE, $contentType);
         if ($contentType == BaseRestApiController::JSON) {
             $response->setJsonContent($content);
         } else {
             $response->setContent($content);
         }
     }
     return $response;
 }
コード例 #6
1
 public static function p($status = 1, $msg = null, $data = [], $code = 200)
 {
     if (method_exists($msg, 'getMessage')) {
         $msg = $msg->getMessage();
     }
     $response = new \Phalcon\Http\Response();
     $response->setHeader("Content-Type", "application/json");
     if ($status) {
         $response->setStatusCode(200);
     } else {
         $response->setStatusCode($code);
     }
     $response->setJsonContent(array('status' => $status == 1 ? 'success' : 'error', 'msg' => $msg, 'data' => $data));
     $response->send();
 }
コード例 #7
1
ファイル: Api.php プロジェクト: webkitz/phalcon-mailgun
 /**
  * @param $data response to send back as JSON with Callback
  * @param bool|true $success
  * @param int $status_code of response default 200
  * @param string $status_message of response default OK
  */
 public function response($data, $success = true, $status_code = 200, $status_message = "OK")
 {
     //new response
     $response = new \Phalcon\Http\Response();
     //header('Access-Control-Allow-Origin: *');
     $response->setStatusCode($status_code, $status_message);
     $response->setContentType('application/json', 'utf-8');
     $response->setHeader('Access-Control-Allow-Origin', '*');
     //encode call
     $json = json_encode(array('success' => $success, 'data' => $data));
     //set response to send back check for callback
     $response->setContent(isset($_GET['callback']) ? "{$_GET['callback']}({$json})" : $json);
     $response->send();
     exit;
     //kill from other processing
 }
コード例 #8
1
 public function prepareTimePickerAction()
 {
     if ($this->request->isPost() && $this->request->isAjax()) {
         $date = $this->request->getPost('date');
         $termin = strtotime($date) + 9 * 60 * 60;
         $termins = array();
         for ($i = 0; $i < 20; $i++) {
             $apps = Application::find(array('conditions' => 'term = ?1', 'bind' => array(1 => date("Y.m.d H:i", $termin))));
             if (count($apps) >= 4) {
                 $termins[date("H:i", $termin)] = 1;
             } else {
                 $termins[date("H:i", $termin)] = 0;
             }
             $termin += 30 * 60;
         }
         $view = clone $this->view;
         $view->start();
         $view->setRenderLevel(View::LEVEL_ACTION_VIEW);
         $view->setParamToView('termins', $termins);
         $view->render('user', 'prepareTimePicker');
         $view->finish();
         $content = $view->getContent();
         $this->view->disable();
         $status = 200;
         $description = 'OK';
         $headers = array();
         $contentType = 'application/json';
         $content = json_encode($content);
         $response = new \Phalcon\Http\Response();
         $response->setStatusCode($status, $description);
         $response->setContentType($contentType, 'UTF-8');
         $response->setContent($content);
         foreach ($headers as $key => $value) {
             $response->setHeader($key, $value);
         }
         return $response;
     }
 }
コード例 #9
1
 public function attachResponseService()
 {
     $this->_di->setShared('response', function () {
         $response = new \Phalcon\Http\Response();
         $response->setHeader('X-Frame-Options', 'SAMEORIGIN');
         $response->setHeader('X-Content-Type-Options', 'nosniff');
         $response->setHeader('X-XSS-Protection', '1; mode=block');
         $response->setHeader('X-Download-Options', 'noopen');
         return $response;
     });
     return $this;
 }
コード例 #10
0
ファイル: MainController.php プロジェクト: sq3hll/github_Api
 public function deleteAction()
 {
     $response = new \Phalcon\Http\Response();
     $delete_url = $this->request->getPost("delete_url");
     $status = Git::deleteRepository($delete_url, $this->session->get('token'));
     return $response->setContent($status);
 }
コード例 #11
0
 public function indexAction()
 {
     $html = $this->view->render('login/index');
     $response = new \Phalcon\Http\Response();
     $response->setContent($html);
     return $response;
 }
コード例 #12
0
 public function getAction()
 {
     // Getting a response instance
     $response = new \Phalcon\Http\Response();
     $feed = $response->setContent($feed->asString());
     //Return the response
     return $response;
 }
コード例 #13
0
 public function table1Action()
 {
     $this->view->disable();
     if ($this->request->isAjax() == true) {
         $response = new \Phalcon\Http\Response();
         $response->setContentType('application/json', 'UTF-8');
         $db_data = new Data();
         $response->setContent($db_data->get_table_data_json($this->request->getPost(), $this->config->table_1->toArray()));
         return $response;
     }
 }
コード例 #14
0
 public function indexAction()
 {
     /*$res = $this->dispatcher->forward(array(
                                      "controller" => "Student",
                                      "action" => "index"
                                  ));
       */
     $response = new \Phalcon\Http\Response();
     $response->redirect("/methodist/student/index");
     return $response;
 }
コード例 #15
0
 public function indexAction()
 {
     $client = new Everyman\Neo4j\Client('localhost', 7474);
     $this->view->disable();
     //Create a response instance
     $response = new \Phalcon\Http\Response();
     //Set the content of the response
     $response->setContent(json_encode($client->getServerInfo()));
     $response->setContentType('application/json', 'UTF-8');
     //Return the response
     return $response;
 }
コード例 #16
0
ファイル: LoginController.php プロジェクト: Altairko/REA
 /**
  * This action authenticate and logs an user into the application
  *
  */
 public function startAction()
 {
     $response = new \Phalcon\Http\Response();
     if ($this->request->isPost()) {
         $email = $this->request->getPost('email');
         $password = $this->request->getPost('password');
         $user = Users::findFirst(array("(email = :email: OR username = :email:) AND password = :password: AND active = 'Y'", 'bind' => array('email' => $email, 'password' => sha1($password))));
         if ($user != false) {
             $this->_registerSession($user);
             return $response->redirect();
         }
         $this->flash->error('Неверный email/пароль');
         return $this->forward('login/index');
     }
     return $response->redirect();
 }
コード例 #17
0
ファイル: AdminController.php プロジェクト: poorman/MyCMS
 public function loginAction()
 {
     if ($this->request->isPost()) {
         //Receiving the variables sent by POST
         $username = $this->request->getPost('username');
         $password = $this->request->getPost('password');
         //Find the user in the database
         $user = Users::findFirst(array("username = :username: AND password = :password: "******"bind" => array('username' => $username, 'password' => md5($password))));
         if ($user != false) {
             $this->_registerSession($user);
             $response = new \Phalcon\Http\Response();
             return $response->redirect("admin");
         } else {
             $this->flash->error('Wrong email/password');
         }
     }
 }
コード例 #18
0
 public function indexAction()
 {
     $client = new Client('localhost', 7474);
     $lat = $this->request->getQuery("lat", "float", 0.0);
     $lng = $this->request->get('lng', "float", 0.0);
     $distance = $this->request->get('distance', "float", 500);
     $offset = $this->request->get('offset', "int", 0);
     $limit = $this->request->get('limit', "int", 5);
     $cache =& $this->di->get('cache');
     $redis_key = implode('|', array('AirportsController', 'indexAction', $lat, $lng, $distance, $offset, $limit));
     try {
         // If Redis is connected - try to get result.
         $result = $cache->get($redis_key);
         $cache_connected = true;
     } catch (Exception $e) {
         $result = false;
         $cache_connected = false;
     }
     if ($result) {
         $result = unserialize($result);
     } else {
         $result = array();
         $query = sprintf("START n=node:geom('withinDistance:[%s, %s, %s]')\n                MATCH n-[r:AVAILABLE_DESTINATION]->()\n                RETURN DISTINCT n\n                SKIP %s LIMIT %s", number_format($lat, 6), number_format($lng, 6), number_format($distance, 1), $offset, $limit);
         $query = new Cypher\Query($client, $query);
         $query = $query->getResultSet();
         foreach ($query as $row) {
             $item = array('id' => $row['n']->getId(), 'distance' => _distance($row['n']->getProperties()['latitude'], $row['n']->getProperties()['longitude'], $lat, $lng));
             foreach ($row['n']->getProperties() as $key => $value) {
                 $item[$key] = $value;
             }
             $result[] = $item;
         }
         if ($cache_connected) {
             $cache->set($redis_key, serialize($result));
         }
     }
     $this->view->disable();
     $response = new \Phalcon\Http\Response();
     // Set the content of the response.
     $response->setContent(json_encode(array('json_list' => $result)));
     $response->setContentType('application/json', 'UTF-8');
     return $response;
 }
コード例 #19
0
 public function deleteAction()
 {
     if ($this->request->isPost() == true) {
         // Access POST data
         $poiId = $this->request->getPost("poiId");
         $poi = Poi::findFirst("id = {$poiId}");
         if ($poi) {
             if ($poi->delete() == false) {
                 echo "POI deleting unsuccessful: \n";
                 foreach ($poi->getMessages() as $message) {
                     echo $message, "\n";
                 }
             } else {
                 echo "POI successfully deleted!";
             }
         }
     }
     $response = new \Phalcon\Http\Response();
     return $response->redirect("poi");
 }
コード例 #20
0
 public function redirectAction()
 {
     $slug = $this->dispatcher->getParam("slug");
     $link = Links::findFirst('token="' . $slug . '"');
     //$check = Counts::findFirst('visitor_ip' => $this->getUserIP(), 'links_id' => $link->id));
     $check = Counts::findFirst(array('visitor_ip=:visitor_ip: AND links_id=:links_id:', 'bind' => array('visitor_ip' => $this->getUserIP(), 'links_id' => $link->id)));
     if (!$check) {
         $counts = new Counts();
         $counts->links_id = $link->id;
         $counts->value = 1;
         $counts->visit_date = date("Y-m-d H:i:s");
         $counts->visitor_ip = $this->getUserIP();
         $counts->save();
         unset($counts);
         $counts_total = count(Counts::find(array("links_id" => $link->id)));
     }
     $link->visitor_count = $counts_total;
     $link->save();
     $this->view->linkurl = $link->longurl;
     $response = new \Phalcon\Http\Response();
     return $response->redirect($link->longurl, true);
 }
コード例 #21
0
ファイル: Security.php プロジェクト: lumberjacks/exchangewolf
 public function beforeDispatch(Event $event, Dispatcher $dispatcher)
 {
     $controller = $dispatcher->getControllerName();
     /* if you are attempting to access login controller, allow it to execute  */
     if ($controller == "login" || $controller == "register") {
         return;
     }
     /* get the username/password from the post  */
     $request = new \Phalcon\Http\Request();
     $username = $request->getPost("username");
     $password = $request->getPost("password");
     $auth_model = new Users();
     /* authenticate if attempt to login has been made */
     if (!empty($username) && !empty($password)) {
         $this->authenticate($username, $password, $auth_model);
     }
     /* logout auth */
     if ($controller == "logout") {
         $this->session->set("authorize", serialize((object) array()));
         $response = new \Phalcon\Http\Response();
         $response->redirect()->sendHeaders();
         exit;
     }
     /* if authentication failed for some reason */
     if (!$this->isAuthenticated()) {
         if ($request->isAjax()) {
             /* send failure response */
             $response = new \Phalcon\Http\Response();
             $response->setContent(json_encode(array('error' => 'invalid_auth')))->send();
             exit;
         } else {
             /* stay on the login page  */
             $dispatcher->forward(array('controller' => 'login', 'action' => 'index'));
             return false;
         }
     }
 }
コード例 #22
0
 public function deleteAction($id)
 {
     $response = new \Phalcon\Http\Response();
     $response->setStatusCode(200, "OK");
     $response->setContent("Town deleted");
     $town = Town::findFirst($id);
     if (!$town) {
         $response->setStatusCode(204, "No Content");
         $response->setContent("");
     } else {
         if (!$town->delete()) {
             $response->setStatusCode(403, "Forbidden");
             $response->setContent("Cannot delete town");
         }
     }
     return $response;
 }
コード例 #23
0
 protected function respondWithStatusCode($code = HttpStatusCode::OK, $message = null)
 {
     $this->view->disable();
     $response = new \Phalcon\Http\Response();
     $response->setStatusCode($code, HttpStatusCode::getMessage($code));
     if ($this->request->isAjax() || $this->clientAcceptsJson()) {
         $data = new \stdClass();
         $data->message = $message;
         $response->setContentType("application/json", "utf-8");
         $response->setJsonContent($data, JSON_PRETTY_PRINT | JSON_NUMERIC_CHECK);
     } else {
         $response->setContent($message);
     }
     return $response;
 }
コード例 #24
0
 /**
  * Process response
  * @param mixed $options array('status', 'message', 'data', 'allow')
  * @return mixed
  */
 public function processResponse($options = array())
 {
     if (empty($options)) {
         return false;
     }
     // Create a response
     $response = new Phalcon\Http\Response();
     // set allow response field
     if (!empty($options['allow']) && is_array($options['allow'])) {
         $response->setRawHeader("Allow: " . implode(",", $options['allow']));
     }
     // Set the Content-Type header
     $response->setContentType('application/json');
     $response->setStatusCode($options['status']);
     // 204 response code should not contain http body
     if ($options['status'] != 204 && !empty($options['payload'])) {
         $response->setContent(json_encode($options['payload']));
     }
     return $response;
 }
コード例 #25
0
 /**
  * Initializes the router
  */
 protected function initRouter()
 {
     $config = $this->di['config'];
     // Not-Found Handler
     $this->app->notFound(function () {
         // Create a response
         $response = new Phalcon\Http\Response();
         // Set the Content-Type header
         $response->setContentType('application/json');
         $response->setStatusCode(404, "Not Found");
         $response->setContent(json_encode(array('status' => 'failure', 'data' => array(), 'error' => array('code' => 404, 'message' => 'Invalid endpoint request'))));
         return $response;
     });
     // Define the routes from config
     foreach ($config['routes'] as $items) {
         // load routes based on controller/action
         $className = $items['controller'];
         $myController = new $className();
         $this->app->{$items}['method']($items['route'], array($myController, $items['action']));
     }
 }
コード例 #26
0
 public function registerSubmitAction()
 {
     if ($this->request->isPost()) {
         $type = $this->request->getPost('type');
         $params = array();
         $ubm = new DtbUserBasic();
         $check_value = true;
         $password = $this->request->getPost('password');
         $nickname = $this->request->getPost('nickname');
         $img_verity = $this->request->getPost('img_verity');
         $res = $this->checkVerity($img_verity);
         if (!$res) {
             $this->flash->error('验证码错误!!');
             return $this->dispatcher->forward(array('controller' => 'user', 'action' => 'register'));
         }
         if ($type == 1) {
             //mobile
             $mobile = $this->request->getPost('mobile');
             $mobile_code = $this->request->getPost('mobile_code');
             if (!$this->_checkRegisterConditon($type, $mobile, '', $password, $mobile_code, $nickname)) {
                 echo "<a href='/user/register'>返回</a>";
                 $response = new Phalcon\Http\Response();
                 $this->response->redirect("/user/register");
             }
             $params = array('nickname' => $nickname, 'password' => md5($password), 'mobile' => $mobile, 'email' => $mobile . '@test.com', 'reg_form' => 1);
         } else {
             $email = $this->request->getPost('email');
             if (!$this->_checkRegisterConditon($type, '', $email, $password, '', $nickname)) {
                 echo "<a href='/user/register'>返回</a>";
                 $response = new Phalcon\Http\Response();
                 $response->redirect("/user/register");
             }
             //email
             $params = array('nickname' => $nickname, 'password' => md5($password), 'email' => $email, 'mobile' => '0', 'reg_form' => 2);
         }
         $res = $ubm->register($user_id, $params, $type);
         if ($res) {
             $this->flash->success('注册成功,请登陆!');
             return $this->dispatcher->forward(array('controller' => 'user', 'action' => 'applyInvest'));
         }
     }
 }
コード例 #27
0
 public function indexAction()
 {
     $response = new \Phalcon\Http\Response();
     $response->redirect("index");
     $response->send();
 }
コード例 #28
0
ファイル: MapfileController.php プロジェクト: benoitlesp/igo
 public function saveAction($r_controller = null, $r_action = null, $r_id = null)
 {
     set_time_limit(180);
     ini_set('memory_limit', '512M');
     $request = new \Phalcon\Http\Request();
     $response = new \Phalcon\Http\Response();
     $previousURL = 'mapfile/process';
     if (!$request->isPost()) {
         return $response->redirect($this->cancelURL);
     }
     $layers = $this->session->get('processData');
     if (!$layers) {
         return $response->redirect($this->cancelURL);
     }
     //Check if a context shoud be created
     $creer_contexte = $request->getPost('creer_contexte', null);
     $igoContexte = null;
     if ($creer_contexte) {
         $contexteName = trim($request->getPost('name', null));
         $contexteCode = trim($request->getPost('code', null));
         $contexteDescription = trim($request->getPost('description', null));
         $onlineResource = trim($request->getPost('onlineResource', null));
         if (!$contexteName) {
             $this->flashSession->error('Veuillez indiquer un nom de contexte.');
         }
         if (!$contexteCode) {
             $this->flashSession->error('Veuillez indiquer un code de contexte.');
         }
         if (!$contexteDescription) {
             $this->flashSession->error('Veuillez indiquer une description du contexte.');
         }
         if (!$onlineResource) {
             $this->flashSession->error('Veuillez indiquer la resource en ligne.');
         }
         $mapServerConfig = $this->getDI()->getConfig()->mapserver;
         $fileName = $mapServerConfig->mapfileCacheDir . $mapServerConfig->contextesCacheDir . trim($contexteCode) . ".map";
         if (file_exists($fileName)) {
             $this->flash->error("Le fichier {$fileName} existe déjà. Choisissez un autre code.");
         }
         $this->session->set('contexteName', $contexteName);
         $this->session->set('contexteCode', $contexteCode);
         $this->session->set('contexteDescription', $contexteDescription);
         $this->session->set('onlineResource', $onlineResource);
         if ($this->flashSession->has('error')) {
             return $response->redirect($previousURL);
         }
         $igoContexte = new IgoContexte();
         $mapfileData = $this->session->get('mapfileData');
         // Substitude contexteCode if provided
         $onlineResource = str_replace("{Code}", $contexteCode, $onlineResource);
         $igoContexte->mf_map_meta_onlineresource = $onlineResource;
         $igoContexte->mf_map_projection = $mapfileData['map']['projection'];
         $igoContexte->nom = $contexteName;
         $igoContexte->code = $contexteCode;
         $igoContexte->description = $contexteDescription;
         $igoContexte->mode = "l";
         //mode Liste
         $igoContexte->generer_onlineresource = true;
     }
     //Save the layers (and optionally a context)
     $mapfileParser = new MapfileParser();
     $data = $mapfileParser->formatSaveData($layers, $this->view->host, $this->view->host_alias);
     try {
         $this->save($data, $igoContexte);
         $this->flashSession->success('Sauvegarde effectuée avec succès!');
     } catch (Exception $e) {
         $this->flashSession->error($e->getMessage());
         return $response->redirect($previousURL);
     }
     $this->clearSession();
 }
コード例 #29
0
ファイル: index.php プロジェクト: nmarley/dashninja-be
                $onlytestnet = "";
            }
            $sql = sprintf("UPDATE cmd_nodes SET VersionID=%d WHERE KeepUpToDate=1{$onlytestnet}", $versionid);
            if ($result = $mysqli->query($sql)) {
                $info2 = $mysqli->info;
                if (is_null($info2)) {
                    $info2 = true;
                }
            } else {
                $info2 = $mysqli->errno . ': ' . $mysqli->error;
            }
            //Change the HTTP status
            $response->setStatusCode(202, "Accepted");
            $response->setJsonContent(array('status' => 'OK', 'data' => array('VersionId' => $versionid, "KeepUpToDate" => $info2)));
        } else {
            $response->setStatusCode(503, "Service Unavailable");
            $response->setJsonContent(array('status' => 'ERROR', 'messages' => array($mysqli->errno . ': ' . $mysqli->error)));
        }
    }
    return $response;
});
// ============================================================================
// End-point not found
// ============================================================================
$app->notFound(function () use($app) {
    $response = new Phalcon\Http\Response();
    $response->setStatusCode(404, "Not Found");
    $response->setJsonContent(array('status' => 'ERROR', 'messages' => array('Unknown end-point')));
    $response->send();
});
$app->handle();
コード例 #30
0
        $response->setStatusCode(500, "Internal Error");
        $errors = array();
        foreach ($status->getMessages() as $message) {
            $errors[] = $message->getMessage();
        }
        $response->setJsonContent(array('status' => 'ERROR', 'messages' => $errors));
    }
    return $response;
});
//eliminamos un entidadcursosala por su id
$application->delete('/api/entidadcursosalas/{id:[0-9]+}', function ($id) use($application) {
    //creamos la consulta con phql
    $phql = "DELETE FROM Entidadcursosala WHERE id = :id:";
    $status = $application->modelsManager->executeQuery($phql, array('id' => $id));
    //creamos una respuesta
    $response = new Phalcon\Http\Response();
    //comprobamos si la eliminación se ha llevado a cabo correctamente
    if ($status->success() == true) {
        $response->setJsonContent(array('status' => 'OK'));
    } else {
        ////en otro caso cambiamos el estado http por un 500
        $response->setStatusCode(500, "Internal Error");
        $errors = array();
        //mostramos los errores
        foreach ($status->getMessages() as $message) {
            $errors[] = $message->getMessage();
        }
        $response->setJsonContent(array('status' => 'ERROR', 'messages' => $errors));
    }
    return $response;
});