public function do_upload($dir = '', $filename = 'userfile', $is_ajax = false) { if (!$this->ion_auth->logged_in() or !$this->ion_auth->is_admin()) { redirect('auth/login', 'refresh'); } else { /* Conf */ $config['upload_path'] = './upload/' . $dir; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = 2048; $config['max_width'] = 1024; $config['max_height'] = 1024; $config['file_ext_tolower'] = TRUE; $this->load->library('upload', $config); /* Breadcrumbs */ $this->breadcrumbs->unshift(2, lang('menu_files'), 'admin/files'); $this->data['breadcrumb'] = $this->breadcrumbs->show(); if (!$this->upload->do_upload($filename)) { /* Data */ $this->data['error'] = $this->upload->display_errors(); if ($is_ajax) { Response::build(-1, 'error', $this->data)->show(); } else { $this->template->admin_render('admin/files/index', $this->data); } } else { /* Data */ $this->data['upload_data'] = $this->upload->data(); if ($is_ajax) { Response::build(-1, 'error', $this->data)->show(); } else { $this->template->admin_render('admin/files/upload', $this->data); } } } }
public function interest($category_id = 1) { $page_num = 3; $page = rand(1, 3); $this->data['questions'] = $this->question_model->get_question(array("question_category_id" => $category_id, "sort_by" => 'update_time', 'sort_direction' => 'desc', "pid" => 'NULL', 'limit' => $page_num, 'offset' => ($page - 1) * $page_num)); Response::build(0, 'ok', $this->data['questions'])->show(); }
} } public function del() { $ret = $this->answer_model->delete_answer(array('id' => $this->input->post('id'))); if ($ret) { Response::build(0, 'ok')->show(); } else { Response::build(-1, "delete error")->show();
// $this->output->enable_profiler(TRUE); } public function del() { $id = $this->input->post("id"); //$result = $this->result_model->get_result(array("id"=>$id)); $ret = $this->result_model->delete_result(array("id" => $id)); if ($ret) { Response::build(0, 'ok', $id)->show(); } else { Response::build(-1, "delete result fail")->show();
public function keepAlive() { if (!$this->isVerified()) { $response = new Response(401, 'You are not verified! Check the documentation.'); $response->build(); return; } $_SESSION['time'] = time(); $response = new Response(200, 'Session is keeped alive for 2 minutes.'); $response->build(); }
public function handle(Request $req, Response $res) : Response { // Skip if it is the path where the user is supposed to sign up if ($this->signUpPath && $this->signUpPath === trim($req->getUrl()->getPath(), '/')) { return $res; } // A way to validate the user credentials is required if (!$this->authStrategy) { throw new \InvalidArgumentException('An authentication strategy must be provided in order to identify the users in the system'); } // Access forbidden if no credentials are provided if (!$_SERVER['PHP_AUTH_USER']) { return $res->build(HttpStatus::Unauthorized, ['WWW-Authenticate' => 'Basic'], ['title' => 'Unauthenticated', 'detail' => 'The information you are trying to access requires authentication']); } $user = $_SERVER['PHP_AUTH_USER']; $pass = $_SERVER['PHP_AUTH_PW']; // Validate the user-provided credentials if (!$this->authStrategy->checkCredentials($user, $pass)) { return $res->build(HttpStatus::Unauthorized, [], ['title' => 'Wrong password', 'detail' => 'The password provided is not correct for the username']); } return $res; }
public function get($date = null) { if ($date == null) { $date = date('j.n.Y'); } if (file_exists(path . 'saved/' . $date . '.json')) { $content = file_get_contents(path . 'saved/' . $date . '.json'); $response = new Response(200, json_decode($content)); $response->build(); } else { $response = new Response(404, 'Date ' . $date . ' does not exist.'); $response->build(); } }
public function __construct() { if (@$_GET['url'] == null) { $response = new Response(400, 'You are wrong here! Check the documentation.'); $response->build(); return; } $url = rtrim($_GET['url'], '/'); $url = filter_var($url, FILTER_SANITIZE_URL); $url = explode('/', $url); if (!file_exists(path . 'modules/' . $url[0] . '.php')) { $response = new Response(404, 'Module ' . $url[0] . ' does not exist! Check the documenation.'); $response->build(); return; } require path . 'modules/' . $url[0] . '.php'; $module = new $url[0](); if ($url[1] == null || !method_exists($module, $url[1])) { $response = new Response(404, 'You are wrong here. Check the documentation.'); $response->build(); return; } switch (sizeof($url) - 2) { case 0: $module->{$url}[1](); break; case 1: $module->{$url}[1]($url[2]); break; case 2: $module->{$url}[1]($url[2], $url[3]); break; case 3: $module->{$url}[1]($url[2], $url[3], $url[4]); break; } }
public function del() { $ret = $this->question_model->delete_question(array("id" => $this->input->post('id'))); if ($ret > 0) { $this->answer_model->delete_answer(array("sub_question_id" => $this->input->post('id'))); Response::build(0, "ok", "删除成功")->show(); } else { Response::build(-1, "删除失败")->show(); } }
public function get() { $content = file_get_contents(path . 'saved/teacher/teacher.json'); $response = new Response(200, json_decode($content)); $response->build(); }