Example #1
0
 public function after($response)
 {
     // If a response has been provided, just go with it
     if (!is_null($response)) {
         return $response;
     }
     // Populate the sidebar
     $this->sidebar = \Admin::getSidebarConfig();
     // Add assets
     $this->data['assets'] = array('js' => \Arr::get($this->assets, 'js', array()), 'css' => \Arr::get($this->assets, 'css', array()));
     // JSON encode the JS
     $this->js['settings'] = $this->getSettings();
     $this->data['js_data'] = json_encode($this->js);
     // Info about the user
     $user = \CMF\Auth::current_user();
     $this->user = array('account' => '/admin/users/' . $user->id . '/edit', 'username' => $user->username, 'super_user' => $user->super_user);
     // Some vital settings
     $this->admin_title = \Lang::get('admin.title', array(), \Config::get("cmf.admin.title", ''));
     $this->base_url = \Admin::$base;
     $this->modules = \Config::get('cmf.admin.modules', false);
     $this->current_module = \Admin::$current_module;
     $this->current_class = \Admin::$current_class;
     $this->dashboard_title = \Lang::get('admin.modules.' . \Admin::$current_module . '.title', array(), \Config::get('cmf.admin.modules.' . \Admin::$current_module . '.title', \Lang::get('admin.common.dashboard', array(), 'Dashboard')));
     $this->headers['X-XSS-Protection'] = 0;
     return \Response::forge(\View::forge($this->template, $this->data, false), $this->status, $this->headers);
 }
Example #2
0
 public function serve($content, $modified = false)
 {
     $cache_last_modified = $modified ? time() : filemtime($this->path);
     $header_modified_since = strtotime(\Input::server('HTTP_IF_MODIFIED_SINCE', 0));
     $status = 200;
     // Set the response headers for cache etc
     $headers = array('Cache-Control' => 'public', 'Last-Modified' => gmdate('D, d M Y H:i:s', $cache_last_modified) . ' GMT', 'Content-Type' => $this->content_type, 'X-UA-Compatible' => 'IE=edge');
     // Still call the before method on the controller... is this a good idea? Perhaps not.
     /* if (isset($this->request) && $controller = $this->request->controller_instance) {
     			if (method_exists($controller, 'before')) $controller->before($content);
     		} */
     // Return 304 not modified if the content hasn't changed, but only if the profiler isn't enabled.
     if (!\Fuel::$profiling) {
         $headers['Content-Length'] = strlen($content);
         if ($header_modified_since >= $cache_last_modified) {
             header('HTTP/1.1 304 Not Modified');
             exit;
         }
     }
     // Send the response
     \Response::forge($content, $status, $headers)->send(true);
     if (\Fuel::$profiling) {
         \Profiler::mark('CMF Cache Served');
     }
     exit;
 }
Example #3
0
 public function action_index($view_path, $id)
 {
     $post_input = Input::post();
     // First of all turn the submitted data into a FuelPHP model representation.
     $form_data_object = new \EBS\Form_Data($post_input);
     // Now go through and save created models and run validation.
     $model_validation = new \EBS\Form_Save_Models($form_data_object->models_and_actions);
     if (!$model_validation->run()) {
         $this->response->highlight_fields = $model_validation->get_highlightfields();
         foreach ($model_validation->database_errors as $database_error) {
             // Create alerts specific to database errors for debugging purposes.
             // Perhaps this should only be shown if in DEV environment.
             $this->response->alerts[] = new \EBS\Response_Alert("There was a database error! Message: {$database_error->getMessage()}", 'danger', '', 0);
         }
     } else {
         // If that's successful, set the response success to true, as we're all done!
         $this->response->success = true;
         // Check if there was a view to generate and send back as well.
         if ($view_path !== null) {
             // Get the path for the view request.
             $view_path = str_replace('_', '/', $view_path);
             $updated_view = new \EBS\Response_View();
             $updated_view->html = Presenter::forge($view_path)->set('id', $id)->render();
             $updated_view->context = Input::post('response_target');
             $this->response->updated_views[] = $updated_view;
         }
     }
     // Encode the response object as JSON and send it back to the UI!
     return Response::forge(json_encode($this->response));
 }
Example #4
0
 public function action_index()
 {
     if (isset($this->field)) {
         $data = array();
         $data['pdu'] = $this->field->power;
         if ($this->tmpl) {
             $data['cables'] = array();
         } else {
             $data['cables'] = Model_Cable::find()->where('type', 2)->where('dev1', $this->field->deviceID)->or_where('dev2', $this->field->deviceID)->get();
         }
         $data['err'] = '';
         if ($this->isSuplly()) {
             $data['maxout'] = 42;
             if (!$this->tmpl) {
                 if ($this->field->device->meta_default_data > 0) {
                     $data['maxout'] = 42;
                 } else {
                     $data['maxout'] = 24;
                 }
             }
             return \Response::forge(\View::forge('power/supply', $data));
         } else {
             return \Response::forge(\View::forge('power/consumer', $data));
         }
     }
 }
Example #5
0
 public function action_login()
 {
     $url_redirect = \Uri::create('system/index/index');
     if (\Auth::check()) {
         \Response::redirect($url_redirect);
     }
     if (\Input::is_ajax()) {
         $val = \Validation::forge('validate_login');
         $val->add_field('email', 'Email', 'required|valid_email');
         $val->add_field('password', 'Password', 'required');
         if ($val->run(array())) {
             if (\Auth::instance()->login(\Input::param('email'), \Input::param('password'))) {
                 if (\Input::param('remember', false)) {
                     \Auth::remember_me();
                 } else {
                     \Auth::dont_remember_me();
                 }
                 $response = array('status' => 'success', 'url' => $url_redirect);
             } else {
                 $messages = \Auth::get_error();
                 $response = array('status' => 'error', 'msg' => $messages);
             }
         } else {
             $messages = $val->error_message();
             $response = array('status' => 'error', 'msg' => $messages);
         }
         return \Response::forge(json_encode($response));
     }
     $this->theme->set_template('login');
     $this->theme->get_template()->set('content', \view::forge('default/login', $this->_arrParam));
 }
Example #6
0
 public function action_index()
 {
     #$data = array();
     #$this->template->title = 'Example Page';
     #$this->template->content = View::forge('main/index', $data);
     return Response::forge(View::forge('main/index'));
 }
Example #7
0
 public function template()
 {
     if (isset($this->view)) {
         if (isset($this->model)) {
             die('Have Model');
             //                return \Response::forge( \View::forge('frontend/post/show/image')->set($this->data, null, false) );
         } elseif (isset($this->collectionModel)) {
             //                print_r($this->collectionModel);
             //                die('Have Models and Views');
             return \Response::forge($this->view->set($this->data, null, false));
         }
     }
     if (is_array($this->data)) {
         // Do array stuff
         $name = strtolower($this->modelName);
         echo $name;
         die('Some Data');
         return \View::forge($name, $this->data);
     }
     echo '<pre>';
     print_r($this);
     die('No Data');
     //		$this->data[$this->modelName] = $this->model::find('all');
     return View::forge($this->modelName, $this->data);
 }
Example #8
0
 public function after($response)
 {
     if (empty($response) or !$response instanceof Response) {
         $response = \Response::forge(\Theme::instance()->render());
     }
     return parent::after($response);
 }
 public function action_banner()
 {
     $banner = Model_Asset::query()->where('id', 22)->get_one();
     $name = $banner->uri . '' . $banner->name;
     $data['image'] = $this->_base64_encode_image($name, $banner->type);
     return \Response::forge(\View::forge('image/advertisement/banner')->set_safe($data));
 }
Example #10
0
 public function action_index()
 {
     if ($_POST) {
         $val = \Validation::forge();
         $val->add_field('room', 'Room id', 'required|min_length[1]|max_length[20]');
         if ($val->run()) {
             \Fuel\Core\Module::load('basic');
             $room = \Basic\Model_Room::find($val->validated('room'));
             if ($room) {
                 $query = \DB::query('select distinct cables.id  from cables, rack, device where rack.room=' . $room->id . ' and device.rack=rack.id and (device.id=cables.dev1 or device.id=cables.dev2)');
                 $cables = $query->as_object()->execute();
                 $cabledata = array();
                 foreach ($cables as $c) {
                     $cab = \Basic\Model_Cable::find($c->id);
                     $dev1 = \Basic\Model_Device::find($cab->dev1);
                     $dev2 = \Basic\Model_Device::find($cab->dev2);
                     array_push($cabledata, array('id' => $cab->id, 'dev1' => $cab->dev1, 'port1' => $cab->port1, 'dev2' => $cab->dev2, 'port2' => $cab->port2, 'name1' => $cab->name1, 'name2' => $cab->name2, 'type' => $cab->type, 'hostname1' => $dev1->hostname, 'hostname2' => $dev2->hostname));
                 }
                 $data['cabledata'] = $cabledata;
                 $data['room'] = $room;
                 return \Response::forge(\View::forge('rack', $data));
             }
         }
     }
 }
Example #11
0
 public function after($response)
 {
     parent::after($response);
     // set the content view
     $this->template->content = View::forge($this->_view, $this->_data);
     // return the response object
     return Response::forge($this->template, $this->_status);
 }
Example #12
0
 /**
  * This method gets called after the action is called
  */
 public function after($response)
 {
     // Make sure the $response is a Response object
     if (!$response instanceof Response) {
         $response = \Response::forge($response, $this->response_status);
     }
     return $response;
 }
Example #13
0
 /**
  * OpenID Connectを利用するログイン処理
  */
 public function action_login($_provider = null)
 {
     if (array_key_exists(Inflector::humanize($_provider), Arr::get($this->_config, 'Strategy'))) {
         new Opauth($this->_config, true);
     } else {
         return Response::forge('サポートされてないStrategy!');
     }
 }
Example #14
0
 public function action_myform()
 {
     $fieldset = \fieldset::forge('form');
     $fieldset->add('title', 'title', array('maxlength' => 50), array(array('required')));
     if (\input::post()) {
         echo \input::post('title');
     }
     return \Response::forge($fieldset);
 }
Example #15
0
File: rest.php Project: wushian/MDD
 public function before()
 {
     parent::before();
     // Some Methods cant have a body
     $this->request->body = null;
     // Which format should the data be returned in?
     $this->request->lang = $this->_detect_lang();
     $this->response = \Response::forge();
 }
Example #16
0
 /**
  * {@inheritdoc}
  */
 public function before()
 {
     $manager = $this->getAuth();
     $uri = $this->getUri();
     if (!$manager->check()) {
         return \Response::forge('redirect', $uri . 'login', 'location', 403);
     }
     \View::setGlobal('admin_uri', $uri);
 }
Example #17
0
 public function action_index()
 {
     $this->dataGlobal['pageTitle'] = __('backend.category.manage');
     // Pagination
     $config = array('pagination_url' => \Uri::current(), 'total_items' => \Model_User::count(), 'per_page' => floor(\Model_User::count() / 2), 'uri_segment' => 'page');
     $this->data['pagination'] = $pagination = \Pagination::forge('authors_pagination', $config);
     // Get categories
     $this->data['authors'] = \Model_User::query()->offset($pagination->offset)->limit($pagination->per_page)->order_by('created_at', 'DESC')->get();
     return \Response::forge(\View::forge('backend/author/index')->set($this->data, null, false));
 }
Example #18
0
 /** 
  * @access  public
  * @return  Response
  */
 public function post_add()
 {
     if ($keyword = \Input::post('keyword')) {
         if (\Collection\Keyword::addKeywordToDB($keyword)) {
             $view = \View::forge('keywords/add_success.twig');
             return \Response::forge($view);
         }
     }
     return $this->get_add();
 }
Example #19
0
 public function action_404()
 {
     Lang::load('error', 'error');
     $output['error_head'] = Lang::get('error.404_error_head');
     $output['error_content'] = Lang::get('error.404_error_content', array('home_link' => Uri::base()));
     // <head> output ----------------------------------------------------------------------------------------------
     $output['page_title'] = Lang::get('error.404_page_title');
     // <head> output ----------------------------------------------------------------------------------------------
     return Response::forge(Theme::instance()->view('error/404_v', $output)->auto_filter(false), 404);
 }
Example #20
0
 public function action_index()
 {
     //device types
     $data['d_type'] = Model_Device_Category::find('all', array('order_by' => array('id' => 'asc')));
     //raid types
     $data['raids'] = Model_Raid_Type::find('all', array('order_by' => array('id' => 'asc')));
     //ram types
     $data['rams'] = Model_Ram_Type::find('all', array('order_by' => array('id' => 'asc')));
     return \Response::forge(\View::forge('windows', $data));
 }
Example #21
0
 public function before()
 {
     parent::before();
     if (!Auth::check()) {
         Response::redirect('index');
     }
     if (Auth::get('group_id') == 6) {
         return Response::forge('index');
     }
 }
Example #22
0
 public function action_add($id = null)
 {
     $this->data['isUpdate'] = $isUpdate = $id !== null ? true : false;
     // Prepare form fieldset
     $form = \Fieldset::forge('category_form', array('form_attributes' => array('class' => 'form-horizontal special')));
     $form->add_model('Blog\\Model_Category');
     $form->add('add', '', array('type' => 'submit', 'value' => $isUpdate ? __('backend.edit') : __('backend.add'), 'class' => 'btn btn-primary'));
     // Get or create the post
     if ($isUpdate) {
         $this->data['category'] = $category = Model_Category::find($id);
         $this->dataGlobal['pageTitle'] = __('backend.category.edit');
     } else {
         $this->data['category'] = $category = Model_Category::forge();
         $this->dataGlobal['pageTitle'] = __('backend.category.add');
     }
     $form->populate($category);
     // If POST submit
     if (\Input::post('add')) {
         $form->validation()->run();
         if (!$form->validation()->error()) {
             // Populate the category
             $category->from_array(array('name' => $form->validated('name'), 'slug' => $form->validated('slug') != '' ? \Inflector::friendly_title($form->validated('slug'), '-', true) : \Inflector::friendly_title($form->validated('name'), '-', true), 'parent_id' => $form->validated('parent_id')));
             if ($category->save()) {
                 // Delete cache
                 \Cache::delete('sidebar');
                 // Category Post count update
                 foreach (Model_Category::find('all') as $category) {
                     $category->post_count = count($category->posts);
                     $category->save();
                 }
                 if ($isUpdate) {
                     //						\Messages::success(__('backend.category.edited'));
                     \Session::set_flash('success', __('backend.category.edited'));
                 } else {
                     //						\Messages::success(__('backend.category.added'));
                     \Session::set_flash('success', __('backend.category.added'));
                 }
                 \Response::redirect_back(\Router::get('admin_category'));
             } else {
                 //					\Messages::error(__('error'));
                 \Session::set_flash('error', __('error'));
             }
         } else {
             // Output validation errors
             foreach ($form->validation()->error() as $error) {
                 echo $error;
                 //					\Messages::error($error);
                 \Session::set_flash('error', $error);
             }
         }
     }
     $form->repopulate();
     $this->data['form'] = $form;
     return \Response::forge(\View::forge('backend/category/add')->set($this->data, null, false));
 }
Example #23
0
 public function action_orderDetails($order_id)
 {
     $order_info = [];
     $order_details = Model_OrderProduct::find('all', array('where' => array(['order_id', $order_id])));
     foreach ($order_details as $order_detail) {
         $product = Model_Product::find($order_detail->product_id);
         $order_info[] = (object) ['id' => $product->id, 'name' => $product->name, 'price' => $product->price, 'quantity' => $order_detail->quantity];
     }
     $data = ['order_info' => $order_info, 'order_id' => $order_id, 'message' => Session::get_flash('message'), 'remove_sure' => Session::get_flash('remove_sure')];
     return Response::forge(View::forge('user/orderDetails.tpl', $data));
 }
 public function after($response)
 {
     !\Request::is_hmvc() and $this->theme->get_template()->set_global($this->dataGlobal);
     // If nothing was returned set the theme instance as the response
     if (empty($response)) {
         $response = \Response::forge($this->theme);
     }
     if (!$response instanceof \Response) {
         $response = \Response::forge($response);
     }
     return parent::after($response);
 }
Example #25
0
 public function action_index()
 {
     if (isset($this->field)) {
         if (!$this->field->network) {
             $prop = array('fieldsetID' => $this->field->id, 'deviceID' => $this->field->device->id, 'nics' => 0, 'vports' => 0, 'ports' => 0, 'uplinks' => 0, 'config_data' => '', 'type' => $this->net_type);
             $this->network = new Model_Device_Network($prop);
             $this->network->save();
         }
         $data = $this->data();
         return \Response::forge(\View::forge('network/windata', $data));
     }
 }
Example #26
0
 public function action_file($size = null, $file_cate = null, $split_num = null, $file_name = null)
 {
     $file_name = sprintf('%s.%s', $file_name, Input::extension());
     $config = array('type' => 'file', 'file_cate' => $file_cate, 'split_num' => $split_num, 'size' => $size, 'file_name' => $file_name);
     $file = new Site_FileMaker($config);
     if (!($data = $file->get_data())) {
         throw new HttpNotFoundException();
     }
     $ext = $file->get_extension();
     $accept_exts = conf('upload.types.file.accept_format');
     return Response::forge($data, 200, array('Content-Type' => $accept_exts[$ext]));
 }
Example #27
0
 public function action_thumbnail($imgId = 0)
 {
     $img = Model_Attach::find($imgId);
     $mime = $img['mime'];
     $body = $img['thumbData'];
     if (isset($mime) && isset($body)) {
         header($mime);
         echo $body;
         return Response::forge($body, 200, array('Content-Type' => $mime));
     }
     return Response::forge($body, 200, array('Content-Type' => $mime));
 }
Example #28
0
File: home.php Project: wxl2012/wx
 public function action_login()
 {
     if (\Auth::check()) {
         $redirect = "/admin";
         if (isset($data['to_url'])) {
             $redirect = $data['to_url'];
         }
         \Response::redirect($redirect);
     }
     \View::set_global(array('menu' => 'admin-home', 'title' => '登录系统', 'action' => 'login'));
     if (\Input::method() == 'POST') {
         if (\Auth::login()) {
             if (\Auth::get_user()->username == 'admin') {
                 \Response::redirect('/admin');
             }
             $employee = \Model_Employee::query()->where('parent_id', \Auth::get_user()->id)->get_one();
             if (!$employee) {
                 \Session::set_flash('msg', ['status' => 'err', 'msg' => '非法登录,多次尝试登录,您的帐户将被封锁!', 'title' => '警告', 'sub_title' => '非法登录', 'icon' => 'exclamation-circle', 'color' => '#d9534f']);
                 return $this->not_login_alert();
             }
             // 保存会话信息: 当前登录人员的身份、所属商户、微信公众号信息
             \Session::set('seller', $employee->seller);
             \Session::set('people', $employee->people);
             \Session::set('employee', $employee);
             // 查询当前商户默认公众号信息
             $accounts = \Model_WXAccount::query()->where(['seller_id' => $employee->seller->id])->get();
             $account = false;
             if (count($accounts) > 1) {
                 foreach ($accounts as $item) {
                     if ($account->is_default == 1) {
                         $account = $item;
                         break;
                     }
                 }
             } else {
                 $account = current($accounts);
             }
             \Session::set('WXAccount', $account);
             //获取API访问令牌
             $result = \handler\common\UrlTool::request(\Config::get('base_url') . 'api/token.json?user_id=' . \Auth::get_user()->id);
             $token = json_decode($result->body);
             \Session::set('access_token', $token->access_token);
             $redirect = "/admin";
             if (isset($data['to_url'])) {
                 $redirect = $data['to_url'];
             }
             \Response::redirect($redirect);
         }
         \Session::set_flash('msg', array('status' => 'err', 'msg' => '登录失败', 'errcode' => 20));
     }
     return \Response::forge(\View::forge("ace/login"));
 }
Example #29
0
 public function action_confirm()
 {
     $user_form = $this->user_form;
     $out = '';
     if (!$user_form->validation()->run()) {
         $view = View::forge('form');
         $view->set('form', $user_form);
         return Response::forge($view);
     } else {
         $view = View::forge('members/index');
         return $view;
     }
 }
Example #30
0
 /**
  * After controller method has run, render the theme template
  *
  * @param  Response  $response
  */
 public function after($response)
 {
     if (!\Input::is_ajax()) {
         // If nothing was returned set the theme instance as the response
         if (empty($response)) {
             $response = \Response::forge(\Theme::instance());
         }
         if (!$response instanceof Response) {
             $response = \Response::forge($response);
         }
         return $response;
     }
     return parent::after($response);
 }