/** * Executes a request. * * @param request Request to execute. * * @return Response Response to send. */ public function execute(Request $request) { try { $segments = $request->getPathSegments(); if (count($segments) > 0) { $firstSegment = $segments[0]; if (array_key_exists($firstSegment, $this->controllers)) { $controller = $this->controllers[$firstSegment]; $controllerRequest = $request->consume(); $resource = $controller->getResource($controllerRequest); if (isset($resource)) { $verb = $request->getVerb(); if (method_exists($resource, $verb)) { return $resource->{$verb}($controllerRequest); } else { return Response::notSupported(); } } } } return Response::notFound(); } catch (\Exception $e) { return Response::error($e->getMessage()); } }
public function get_remove_from_favorites($page_id) { if (Favorite::remove($page_id)) { return Redirect::to("page/{$page_id}")->with('removed', true); } return Response::error('500'); }
/** * Test the Response::error method. * * @group laravel */ public function testErrorMethodSetsContentToErrorView() { $response = Response::error('404', array('name' => 'Taylor')); $this->assertEquals(404, $response->status()); $this->assertEquals('error.404', $response->content->view); $this->assertEquals('Taylor', $response->content->data['name']); }
public static function required($available = false, $function) { if ($available === false) { Response::error('Missing parameters. Can not execute function ' . $function); } return true; }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreateClient() { $hU = new HttpUtils(); if ($hU->isAjaxRequest() == false) { Response::error("not allowed ;)"); } if (isset($_POST["clientName"]) == false || isset($_POST["clientEmail"]) == false) { Response::ok(CJSON::encode(array("resultado" => Constants::RESULTADO_OPERACION_FALLA, "detalle" => "Faltan parámetros obligatorios"))); } $cl = Cliente::model()->findAll("email=:email", array(':email' => $_POST["clientEmail"])); if (sizeof($cl) > 0) { Response::ok(CJSON::encode(array("resultado" => Constants::RESULTADO_OPERACION_FALLA, "detalle" => "Cliente {$_POST["clientEmail"]} ya registrado en el sistema"))); } $cl = new Cliente(); $cl->surname = ""; $cl->comments = ""; $cl->streetaddress = ""; $cl->name = $_POST["clientName"]; $cl->email = $_POST["clientEmail"]; if ($cl->save()) { Response::ok(CJSON::encode(array("resultado" => Constants::RESULTADO_OPERACION_EXITO, "detalle" => "Cliente {$cl->email} registrado con éxito"))); } else { Response::ok(CJSON::encode(array("resultado" => Constants::RESULTADO_OPERACION_FALLA, "detalle" => "Error registrando cliente {$cl->email} en el sistema"))); } }
public function action_edit($id) { if (Auth::check() && Session::has('id')) { $account = Account::find(Session::get('id')); $location = Location::find($id); if (Input::has('address') && Input::has('city') && Input::has('postal_code')) { if ($account->id == $location->account_id) { Input::has('address') ? $location->address = strip_tags(Input::get('address')) : ($location->address = ''); Input::has('city') ? $location->city = strip_tags(Input::get('city')) : ($location->city = ''); Input::has('postal_code') ? $location->postal_code = strip_tags(Input::get('postal_code')) : ($location->postal_code = ''); $location->save(); return Redirect::to("/account/myLocations"); } else { return Redirect::to("/account/myLocations"); } } else { if ($location->account_id == $account->id) { $locations = Location::all(); $view = View::make('location.edit.index')->with('title', 'Edit Location')->with('location', $location)->with('locations', $locations); return $view; } else { return Response::error('403'); } } } else { return Redirect::to('/'); } }
public function page($slug = '') { // allow admin to view unpublished posts if (Users::authed() === false) { $params['status'] = 'published'; } // if no slug is set we will use our default page if (empty($slug)) { $params['id'] = Config::get('metadata.home_page'); } else { $params['slug'] = $slug; } // if we cant find either it looks like we're barney rubble (in trouble) if (($page = Pages::find($params)) === false) { return Response::error(404); } // store our page for template functions IoC::instance('page', $page, true); // does the current page host our posts? if ($page->id == Config::get('metadata.posts_page')) { // render our posts template return Template::render('posts'); } // render our page template Template::render('page'); }
public function handle($request, Closure $next) { if (!Request::ajax()) { return Response::error('404'); } return $next($request); }
function verifyOrgAccess($orgName) { global $dataporten; if (strcasecmp($orgName, $dataporten->getUserOrg()) !== 0) { Response::error(401, $_SERVER["SERVER_PROTOCOL"] . ' 401 Unauthorized (request mismatch org/user). '); } }
/** * Method that returns current response array. * @return array */ public static function get() { if (empty(self::$response)) { Response::error(ErrorCodes::EMPTY_RESPONSE); } return self::$response; }
public function render($slug = null, $check_restrictions = true) { if ($slug == null) { $slug = $this->page_slug; } if ($slug == '/' or empty($slug)) { $slug = 'home'; } if ($slug == '404') { //page not found. Do we have a 404 page? really? :) $page = Model\Page::where('slug', '=', '404')->first(); if (isset($page) and count($page) > 0) { $this->data['meta_title'] = $page->title; $this->data['meta_description'] = $page->meta_description; $this->data['meta_keywords'] = $page->meta_keywords; $this->data['page_content'] = $page->body; return $this->theme->render('pages::frontend.page', $this->data); } else { // How embarrassing we dont have a 404 page :) // Return default framework 404 return Response::error('404'); } } $page = Model\Page::where('slug', '=', $slug)->first(); if (!isset($page) or empty($page)) { $page = Model\Page::where('slug', '=', '404')->first(); } $page_access = explode(',', $page->restricted_to); if (Restriction::passes($page_access, new Auth())) { if (isset($page) and count($page) > 0) { $this->data['meta_title'] = $page->title; $this->data['meta_description'] = $page->meta_description; $this->data['meta_keywords'] = $page->meta_keywords; $this->data['page_content'] = $page->body; return $this->theme->render('pages::frontend.page', $this->data); } else { //page not found. Do we have a 404 page? really? :) $page = Model\Page::where('slug', '=', '404')->first(); if (isset($page) and count($page) > 0) { return Redirect::to('404'); } else { // How embarrassing we dont have a 404 page :) // Return default framework 404 return Response::error('404'); } } } else { // not allowed to view page //page not found. Do we have a 404 page? really? :) $page = Model\Page::where('slug', '=', '404')->first(); if (isset($page) and count($page) > 0) { return Redirect::to('404'); } else { // How embarrassing we dont have a 404 page :) // Return default framework 404 return Response::error('404'); } } }
/** * @param $dir */ static function mkdir($dir) { if (!is_dir($dir)) { if (!mkdir($dir, 0777, true)) { Response::error('Failed to create dir:' . $dir); } } }
/** * @brief doAction 请求分发处理 * * @param $params 传入参数 * * @return void */ public function doAction($params) { if (method_exists($this, $params['do'] . 'Do')) { $this->{$params['do'] . 'Do'}(); } else { Response::error(404); } }
public function action_view($slug = '') { $post = Post::where_slug($slug)->first(); if (!$post) { return Response::error('404'); } return $this->layout->nest('content', 'blog::post', array('post' => $post)); }
public function get_index() { $user = Auth::user(); if (!$user) { return Response::error('404'); } else { $this->layout->nest('content', 'user.account', array('user' => $user)); } }
function verifyOrgAccess() { global $feide; if (!$feide->isUserSuperAdmin()) { Response::error(401, $_SERVER["SERVER_PROTOCOL"] . ' 401 Unauthorized (USER is missing required access rights). '); } if (!$feide->hasAdminScope()) { Response::error(401, $_SERVER["SERVER_PROTOCOL"] . ' 401 Unauthorized (CLIENT is missing required scope). '); } }
public function deleteBudget($id) { $budget = Auth::user()->budgets()->find($id); if ($budget) { $budget->delete(); return Redirect::to('/home/budgets'); } else { return Response::error(404); } }
public function post_issue_upload_attachment() { $user_id = Crypter::decrypt(str_replace(' ', '+', Input::get('session'))); Auth::login($user_id); if (!Auth::user()->project_permission(Input::get('project_id'))) { return Response::error('404'); } Project\Issue\Attachment::upload(Input::all()); return true; }
public static function input() { if (self::verb() === 'post' || self::verb() === 'put') { $data = json_decode(file_get_contents('php://input')); if ($data === null) { Response::error(400); } return $data; } return false; }
public function action_show($id) { if (is_numeric($id)) { $page = Page::where('id', '=', $id)->first(); } else { $page = Page::where('slug', '=', $id)->first(); } if ($page) { return View::make('admin.pages.show')->with('content', $page); } return Response::error('404'); }
/** * Login * * @return Response */ public function post_login() { $rules = array('email' => 'required|email', 'password' => 'required'); $validator = new Validator(Input::all(), $rules); if (!$validator->valid()) { return Response::json((array) $validator->errors->messages, 400); } if (Auth::attempt(Input::get('email'), Input::get('password'))) { return Response::json(Auth::$token); } return Response::error(401); }
public function action_show($segment) { if (is_numeric($segment)) { $post = Post::where('id', '=', $segment)->first(); } else { $post = Post::where('slug', '=', $segment)->first(); } if ($post) { return View::make('admin.posts.show')->with('content', $post); } return Response::error('404'); }
public function postFacebook() { $userProfile = $this->facebookService->getUserProfile(); if ($userProfile) { $user = $this->registerService->registerFacebook($userProfile); Auth::login($user, true); $this->getTokenAndUpdateLoginTime(); return Response::json(['status' => 'ok', 'message' => 'Logged in with facebook']); } else { return Response::error('Facebook log in failed'); } }
public function __construct() { try { $adminData = self::getAdminCredentials(); define('ADMIN_USERNAME', $adminData['username']); define('ADMIN_PASSWORD', $adminData['password']); if (file_exists($this->getInstallFilePath())) { View::share('installFileExistsError', "You must remove the file '" . self::INSTALL_FILE . "' on the script's base folder for security reasons."); } } catch (Exception $e) { die(Response::error("<h4>Original error message:</h4>" . $e->getMessage(), "Error loading admin config. Check Admin config file: /protected/app/config/admin.php")); } }
public function get_view($who = null, $action = 'page') { $withUser = Auth::user(); if (!is_null($who) and is_numeric($who) and !($withUser = User::find($who))) { return Response::error('404'); } if ($action == 'popup') { $this->layout = 'layouts.simple'; $this->layout = $this->layout(); } $users = User::get(); return $this->layout->nest('content', 'user.profile', array('User' => $withUser, 'Friends' => $users)); }
/** * This method checks to see if a view exists and if it does loads it along with any * associated data from the database. It then checks to see if a function exists for * the passed in page name (substituting dashes for underscores and runs that) if it exists. * @param string $page The page name * @param string $variable Allows us to pass a second variable to things * @return view Ideally a view of some kind */ public function get_index($page = 'home', $variable = false) { $this->data['page'] = Page::where('slug', '=', $page)->first(); $function = strtolower(Request::method() . '_' . str_replace('-', '_', $page)); if (method_exists($this, $function)) { $this->{$function}($variable); } else { if (View::exists('site.' . $page)) { return View::make('site.' . $page, $this->data); } else { return Response::error('404'); } } }
public function postDevice() { if (Input::has('device_type') && Input::has('token')) { $deviceType = Input::get('device_type'); $token = Input::get('token'); $user = Auth::getUser(); $user->device_type = $deviceType; $user->device_token = $token; $user->save(); return Response::ok($user); } else { return Response::error('Missing parameters'); } }
/** * Open MSSQL connection */ private function getConnection() { // $connection = mssql_connect($this->config['host'], $this->config['user_write'], $this->config['pass']); // if (!$connection) { Response::error(500, $_SERVER["SERVER_PROTOCOL"] . ' DB connection failed (SQL).'); } // if (!mssql_select_db($this->config['db'])) { Response::error(500, $_SERVER["SERVER_PROTOCOL"] . ' DB table connection failed (SQL).'); } return $connection; }
/** * TODO allow string(?), array and PHP7 generators for source of username password */ private static function auth(array $source) { $user = $_SERVER['PHP_AUTH_USER']; $password = $_SERVER['PHP_AUTH_PW']; if (empty($source)) { Response::error(401); } if (!array_key_exists($user, $source)) { Response::error(401); } if ($source[$user] != $password) { Response::error(401); } }
public function get_index($categoryParent, $categoryChild = null) { //Load details of the passed category $parentCategoryDetails = Category::where('curl', '=', $categoryParent)->first(); if ($categoryChild == null) { $childCategoryDetails = null; } else { $childCategoryDetails = Category::where('curl', '=', $categoryChild)->first(); } //Gets all articles in the default Sub Category if (is_null($parentCategoryDetails)) { return Response::error('404'); } if (is_null($childCategoryDetails)) { $allarticles = Category::find($parentCategoryDetails->id)->Article()->where("status", '=', '1')->get(); } else { $allarticles = Category::find($childCategoryDetails->id)->Article()->where("status", '=', '1')->get(); } //Pushes all articles within the Sub category of a parent Category if (is_null($childCategoryDetails)) { $inner_categories = $parentCategoryDetails->InnerCategory()->get(); foreach ($inner_categories as $innercat) { $allarticlesinner = Category::find($innercat->id)->Article()->get(); foreach ($allarticlesinner as $innercatarticles) { array_push($allarticles, $innercatarticles); } } } //A sort on articles using the POSTed ID usort($allarticles, 'cmsHelper::sortById'); $allarticles = cmsHelper::bakeArticleForViewers($allarticles); //make and return the view return View::make('visitor.categorylist', array('allarticles' => $allarticles, 'parentCategoryDetails' => $parentCategoryDetails, 'childCategoryDetails' => $childCategoryDetails)); }