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); } }
/** * 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]); }
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; } }