FuelPHP Bin
Sign in
Public
PHP
Save
<?php class Controller_Private extends \Controller { public $layout = 'admin'; public $template = 'layouts/default'; public $data = array(); public function before() { if (\Input::is_ajax()) { return parent::before(); } // Initial configuration #\Package::load('nvutility'); $this->theme = \Theme::instance(); $this->theme->active($this->layout); $this->theme->set_template($this->template); #\Theme::instance()->active('private-theme'); #\Theme::instance()->set_template($this->template); #\Theme::instance()->asset->add_path('upload/'); // Set empty values to avoid errors // To Check: Benötigt??? $this->data['template_values'] = array(); $this->data['site_values'] = array(); $this->data['page_values'] = array(); // Setting authorization => TODO!!! #$permission = array($this->request->controller, $this->request->action); #$roles = \Config::get('simpleauth.roles', array()); $auth_id = \Auth::instance()->get_user_id(); $this->global_user = Model_User::find($auth_id[1]); // User isn't logged in if(!\Auth::check()) { \Session::set_flash('error', 'User isn\'t logged in!'); \Debug::dump(\Auth::check()); #die; \Response::redirect('admin/login'); } // Check if user can access this section => TODO!!! // if(!\NVUtility\NVPermission::is_allowed($permission)) // { // // Check if user can access admin section // if(\NVUtility\NVPermission::is_allowed(array('main', $roles['main']['dashboard']))) // { // \Session::set_flash('error', 'You can\' access this section.'); // \Response::redirect('admin/dashboard'); // } // else // { // \Session::set_flash('error', 'You can\' access this section.'); // \Response::redirect('admin/login'); // } // } // Set variables $this->data['template_values']['title'] = 'Site Admin Title'; $this->data['template_values']['subtitle'] = 'Default Admin subtitle'; $this->data['template_values']['author'] = 'Default Admin Author'; $this->data['template_values']['description'] = 'Default Admin description'; $this->data['template_values']['keywords'] = 'Default Admin keywords'; $this->data['site_values']['global_user'] = $this->global_user; // Set template #\Theme::instance()->set_partial('header', 'private/_global/header'); $this->theme->set_partial('navigation', 'partials/navigation'); $this->theme->set_partial('messages', 'partials/messages'); } public function action_login() { \Debug::dump(\Auth::check()); die; // already logged in? if (\Auth::check()) { // yes, so go back to the page the user came from, or the // application dashboard if no previous page can be detected #\Messages::info(__('login.already-logged-in')); \Session::set_flash('info', 'login.already-logged-in'); #\Response::redirect_back('admin/dashboard'); } // was the login form posted? if (\Input::method() == 'POST') { // check the credentials. if (\Auth::instance()->login(\Input::param('username'), \Input::param('password'))) { // did the user want to be remembered? if (\Input::param('remember', false)) { // create the remember-me cookie \Auth::remember_me(); } else { // delete the remember-me cookie if present \Auth::dont_remember_me(); } // logged in, go back to the page the user came from, or the // application dashboard if no previous page can be detected \Response::redirect_back('dashboard'); } else { // login failed, show an error message #\Messages::error(__('login.failure')); Session::set_flash('error', e(__('login.failure'))); } } \Debug::dump(\Auth::check()); die; // display the login page #return \View::forge('private/login'); $this->theme->set_partial('content', 'private/login'); } public function action_dashboard() { \Session::set_flash('info', 'Dashboard'); $this->theme->set_partial('content', 'private/dashboard'); } public function action_logout() { \Debug::dump(\Auth::check()); die; // remove the remember-me cookie, we logged-out on purpose \Auth::dont_remember_me(); // logout \Auth::logout(); // inform the user the logout was successful #\Messages::success(__('login.logged-out')); Session::set_flash('success', e(__('login.logged-out'))); // and go back to where you came from (or the application // homepage if no previous page can be determined) \Response::redirect_back(); } public function after($response) { if (!\Input::is_ajax()) { \Theme::instance()->set_info('data', $this->data); if (empty($response)) { $response = \Response::forge(\Theme::instance()); } } return parent::after($response); } }