Ejemplo n.º 1
0
 public static function sessioninit()
 {
     // See if we have passed in a access_token and an account id.
     if (Input::get('access_token') && Input::get('account_id')) {
         $access_token = Input::get('access_token');
         $account_id = Input::get('account_id');
     } else {
         // See if we have a session. If Not do something about it.
         if (!Session::get('AccountId') || !Session::get('AccessToken')) {
             die(header('location: ' . Config::get('site.login_url')));
         }
         $access_token = Session::get('AccessToken');
         $account_id = Session::get('AccountId');
     }
     // Is this a multi tenant setup? If so set the account.
     if (Config::get('cloudmanic.account')) {
         if (!(self::$account = \Accounts::get_by_id($account_id))) {
             $data = array('status' => 0, 'errors' => array());
             $data['errors'][] = 'Account not found.';
             return \Laravel\Response::json($data);
         }
     }
     // Validate the access_token
     if (!($user = Users::get_by_access_token($access_token))) {
         $data = array('status' => 0, 'errors' => array());
         $data['errors'][] = 'Access token not valid.';
         return \Laravel\Response::json($data);
     } else {
         self::_do_user($user);
     }
 }
Ejemplo n.º 2
0
 /**
  * Prepares the response before sending to the browser.
  * 
  * @return Laravel\Response
  */
 public function prepare()
 {
     $collection = new Collection(null);
     $asset = $this->getAssetFromUri(URI::current());
     if (!($asset = $collection->add($asset))) {
         return;
     }
     // Create a new LaravelResponse object with the contents of the asset. Once we have the
     // response object we can adjust the headers before sending it to the browser.
     $this->response = new LaravelResponse($collection->compile($asset->getGroup()));
     switch ($asset->getGroup()) {
         case 'style':
             $this->response->header('content-type', 'text/css');
             break;
         case 'script':
             $this->response->header('content-type', 'application/javascript');
             break;
     }
     return $this;
 }
Ejemplo n.º 3
0
 /**
  * Return an error page, optionally with data/message
  *
  * @param  int           HTTP status code
  * @param  array|string  Data or message
  */
 public static function error($status = 500, $data = array())
 {
     is_string($data) && ($data = array('message' => $data));
     $data['error'] = true;
     if (Request::ajax() || Request::accepts('application/json')) {
         return parent::json($data, $status);
     }
     if ($status == 404) {
         return parent::error($status, $data);
     }
     return \Event::first('response.error', [$status, $data]);
 }
Ejemplo n.º 4
0
 /**
  * Call a given route and return the route's response.
  *
  * @return Response
  */
 public function call()
 {
     // The route is responsible for running the global filters, and any
     // filters defined on the route itself, since all incoming requests
     // come through a route (either defined or ad-hoc).
     $response = Filter::run($this->filters('before'), array(), true);
     if (is_null($response)) {
         $response = $this->response();
     }
     // We always return a Response instance from the route calls, so
     // we'll use the prepare method on the Response class to make
     // sure we have a valid Response instance.
     $response = Response::prepare($response);
     Filter::run($this->filters('after'), array($response));
     return $response;
 }
 /**
  * Magic Method to handle calls to undefined controller functions.
  */
 public function __call($method, $parameters)
 {
     return Response::error('404');
 }
Ejemplo n.º 6
0
 /**
  * Call a given route and return the route's response.
  *
  * @return Response
  */
 public function call()
 {
     // Since "before" filters can halt the request cycle, we will return
     // any response from the before filters. Allowing filters to halt the
     // request cycle makes tasks like authorization convenient.
     //
     // The route is responsible for running the global filters, and any
     // filters defined on the route itself. Since all incoming requests
     // come through a route (either defined or ad-hoc), it makes sense
     // to let the route handle the global filters. If the route uses
     // a controller, the controller will only call its own filters.
     $before = array_merge(array('before'), $this->filters('before'));
     $response = Filter::run($before, array(), true);
     if (is_null($response) and !is_null($response = $this->response())) {
         if ($response instanceof Delegate) {
             $response = Controller::call($response->destination, $this->parameters);
         }
     }
     if (!$response instanceof Response) {
         $response = new Response($response);
     }
     // Stringify the response. We need to force the response to be
     // stringed before closing the session, since the developer may
     // be using the session within their views, so we cannot age
     // the session data until the view is rendered.
     $response->content = $response->render();
     $filters = array_merge($this->filters('after'), array('after'));
     Filter::run($filters, array($response));
     return $response;
 }
Ejemplo n.º 7
0
 public function api_response($data = null, $status = 1, $errors = NULL)
 {
     // First we see if we should redirect instead of returning the data.
     if (Input::get('redirect_success')) {
         $base = URL::base() . '/' . Input::get('redirect_success');
         $url = $this->_filter_redirect_url($base, $data);
         return Redirect::to($url);
     }
     // Setup the return array
     $rt = array();
     $rt['status'] = $status;
     $rt['data'] = !is_null($data) ? $data : array();
     $rt['filtered'] = 0;
     $rt['total'] = 0;
     // Set errors.
     if (is_null($errors)) {
         $rt['errors'] = array();
     } else {
         // Format the errors
         foreach ($errors as $key => $row) {
             // You can have more than one error per field.
             foreach ($row as $key2 => $row2) {
                 $rt['errors'][] = array('field' => $key, 'error' => $row2);
             }
         }
     }
     // Format the return in the output passed in.
     switch (Input::get('format')) {
         case 'php':
             return '<pre>' . print_r($rt, TRUE) . '</pre>';
             break;
         case 'data':
             return $rt;
             break;
         default:
             return Response::json($rt);
             break;
     }
 }
Ejemplo n.º 8
0
 static function ignoredHeadersOf(\Laravel\Response $response)
 {
     $headers = $response->headers()->keys();
     return array_diff($headers, static::$insignificantHeaders);
 }
Ejemplo n.º 9
0
 /**
  * Send the headers and content of the response to the browser.
  *
  * @return void
  */
 public function send()
 {
     // Dump all output buffering, this ensures
     // that symphony will send our redirect headers
     // properly if we've outputted any content from
     // within Laravel.
     while (ob_get_level() > 0) {
         ob_end_clean();
     }
     return parent::send();
 }
Ejemplo n.º 10
0
 public function call()
 {
     $response = Filter::run($this->filters('before'), array(), true);
     if (is_null($response)) {
         $response = $this->response();
     }
     $response = Response::prepare($response);
     Filter::run($this->filters('after'), array(&$response));
     return $response;
 }
Ejemplo n.º 11
0
 public static function exception($exception, $trace = true)
 {
     static::log($exception);
     ob_get_level() and ob_end_clean();
     $message = $exception->getMessage();
     $file = $exception->getFile();
     if (str_contains($exception->getFile(), 'eval()') and str_contains($exception->getFile(), 'laravel' . DS . 'view.php')) {
         $message = 'Error rendering view: [' . View::$last['name'] . ']' . PHP_EOL . PHP_EOL . $message;
         $file = View::$last['path'];
     }
     if (Config::get('error.detail')) {
         $response_body = "<html><h2>Unhandled Exception</h2>\n\t\t\t\t<h3>Message:</h3>\n\t\t\t\t<pre>" . $message . "</pre>\n\t\t\t\t<h3>Location:</h3>\n\t\t\t\t<pre>" . $file . " on line " . $exception->getLine() . "</pre>";
         if ($trace) {
             $response_body .= "\n\t\t\t\t  <h3>Stack Trace:</h3>\n\t\t\t\t  <pre>" . $exception->getTraceAsString() . "</pre></html>";
         }
         $response = Response::make($response_body, 500);
     } else {
         $response = Event::first('500');
         $response = Response::prepare($response);
     }
     $response->render();
     $response->send();
     $response->foundation->finish();
     exit(1);
 }