FuelPHP Bin
<?php class Controller_Admin extends Controller_Base { // Initial template settings public $layout = 'adminflare'; public $template = 'layouts/dashboard'; public function before() { parent::before(); // Initial template configuration $this->theme->active($this->layout); $this->theme->set_template($this->template); // Get current segments $segments = \Uri::segments(); if (empty($segments)) $segments[0] = 'homepage'; // Set template variables $this->data['template']['title'] = 'Site Title'; $this->data['template']['subtitle'] = 'Default subtitle'; $this->data['template']['author'] = 'Default Author'; $this->data['template']['description'] = 'Default description'; $this->data['template']['keywords'] = 'Default keywords'; $this->data['template']['segments'] = $segments; $this->theme->get_template()->set('data', $this->data); // Set template partials $this->theme->set_partial('navigation', 'partials/navigation'); $this->theme->set_partial('messages', 'partials/messages'); //Checking authorisation to see Admin section or go back to login if (Request::active()->controller !== 'Controller_Admin' or ! in_array(Request::active()->action, array('login', 'logout'))) { if (Auth::check()) { $admin_group_id = Config::get('auth.driver', 'Simpleauth') == 'Ormauth' ? 6 : 100; if ( ! Auth::member($admin_group_id)) { Session::set_flash('error', e('You don\'t have access to the admin panel')); Response::redirect('/'); } } else { Response::redirect('admin/login'); } } } public function action_login() { // Build the Login Form // $fieldset = \Fieldset::forge(); // $fieldset->add('username', 'Username', array('placeholder' => 'Username')); // $fieldset->add('password', 'Password', array('type' => 'password', 'placeholder' => 'Password')); // $fieldset->add(\Config::get('security.csrf_token_key'), \Security::fetch_token(), array('type' => 'hidden'), array('required')); // $fieldset->add('submit', '', array('type' => 'button', 'value' => 'Sign In', 'class' => 'btn btn-primary btn-block')); // Already logged in #Auth::check() and Response::redirect('admin/dashboard'); // 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 \Session::set_flash('info', 'login.already-logged-in'); \Response::redirect_back('admin/dashboard'); } $val = \Validation::forge(); #\Debug::dump($val); \Debug::dump(Input::method()); if (Input::method() == 'POST') { \Debug::dump(Input::method()); die; \Session::set_flash('info', 'Has form been posted?'); $val->add('username', 'Username')->add_rule('required'); $val->add('password', 'Password')->add_rule('required'); \Debug::dump($val); if ($val->run()) { \Session::set_flash('info', 'Validation was made'); $auth = Auth::instance(); // check the credentials. This assumes that you have the previous table created if (Auth::check() or $auth->login(Input::post('username'), Input::post('password'))) { // credentials ok, go right in if (Config::get('auth.driver', 'Simpleauth') == 'Ormauth') { $current_user = Model\Auth_User::find_by_username(Auth::get_screen_name()); } else { $current_user = Model_User::find_by_username(Auth::get_screen_name()); } Session::set_flash('success', e('Welcome, '.$current_user->username)); Response::redirect('admin'); } else { #$this->template->set_global('login_error', 'Fail'); \Session::set_flash('error', 'login_error'); } } else { \Session::set_flash('info', 'Validation NOT successful'); \Debug::dump($val->input()); \Debug::dump($val->validated()); \Debug::dump($val->error()); } } // Display the login page $view = \View::forge('admin\login'); #$view->set('form', $fieldset->form()->build(), false); $this->theme->set_template('layouts/login'); $this->theme->set_partial('content', $view); } /** * The logout action. * * @access public * @return void */ public function action_logout() { Auth::logout(); Response::redirect('admin'); } /** * The index action. * * @access public * @return void */ public function action_index() { Response::redirect('admin/dashboard'); } public function action_dashboard() { // Set variables $this->data['page']['headline'] = 'Dashboard'; $this->data['page']['subline'] = 'Adminflare Backend'; $view = \View::forge('admin\dashboard'); $this->theme->set_partial('content', $view)->set('data', $this->data); } public function after($response) { // If no response object was returned by the action, if (empty($response) or ! $response instanceof Response) { // render the defined template $response = \Response::forge(\Theme::instance()->render()); } return parent::after($response); } } /* End of file admin.php */