Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app/classes/controller/base:
- Controller_Base_Base:
- <?php
- class Controller_Base_Base extends \Controller_Hybrid
- {
- public function before()
- {
- parent::before();
- // Assign current_user to the instance so controllers can use it
- $this->current_user = \Auth::check()
- ? (\Config::get('auth.driver', 'Simpleauth') == 'Ormauth'
- ? \Model\Auth_User::find_by_username(\Auth::get_screen_name())
- : \Model_User::find_by_username(\Auth::get_screen_name()))
- : null;
- // Set a global variables so views can use it
- \View::set_global('current_user', $this->current_user);
- \View::set_global('site_name', 'Nikita CMS');
- }
- }
- <?php
- class Controller_Base_Admin extends \Controller_Base_Base
- {
- public function before()
- {
- parent::before();
- }
- }
- <?php
- class Controller_Base_Public extends \Controller_Base_Base
- {
- public function before()
- {
- parent::before();
- }
- }
- Module Admin:
- modules/admin/classes/controller:
- <?php
- namespace Admin;
- class Controller_Base extends \Controller_Base_Admin
- {
- public function before()
- {
- parent::before();
- }
- }
- <?php
- namespace Admin;
- class Controller_Admin extends Controller_Base
- {
- // Set the template name.
- public $template = 'admin/template';
- /**
- * The before method.
- *
- * @access public
- * @return void
- */
- public function before()
- {
- parent::before();
- // Check to see if user is logged in
- 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('/');
- }
- }
- // Not logged in send user to login
- else
- {
- //echo 'module admin before';
- //exit;
- \Response::redirect('admin/login');
- }
- }
- }
- /**
- * The login action.
- *
- * @access public
- * @return void
- */
- public function action_login()
- {
- // Already logged in
- \Auth::check() and \Response::redirect('admin');
- //echo 'action_login';
- //exit;
- $val = \Validation::forge();
- if (\Input::method() == 'POST')
- {
- // Validation form rules
- $val->add('email', 'Email or Username')
- ->add_rule('required');
- $val->add('password', 'Password')
- ->add_rule('required');
- if ($val->run())
- {
- $auth = \Auth::instance();
- //echo 'module admin before';
- //exit;
- // check the credentials. This assumes that you have the previous table created
- if (\Auth::check() or $auth->login(\Input::post('email'), \Input::post('password')))
- {
- // credentials ok, go right in, it is a Ormauth login
- if (\Config::get('auth.driver', 'Simpleauth') == 'Ormauth')
- {
- $current_user = \Model\Auth_User::find_by_username(\Auth::get_screen_name());
- }
- // It is a Simpleauth login.
- //else
- //{
- // $current_user = Model\User::find_by_username(\Auth::get_screen_name());
- //}
- // Set the flash message an the current user name
- \Session::set_flash('success', e('Welcome, '.$current_user->username));
- \Response::redirect('admin');
- }
- // Else it is an Error!
- else
- {
- $this->template->set_global('login_error', 'Fail');
- }
- }
- }
- //echo 'module admin before';
- //exit;
- $this->template->title = 'Login';
- $this->template->content = \View::forge('admin/login', array('val' => $val), false);
- }
- /**
- * The register action.
- *
- * @access public
- * @return void
- */
- public function action_register()
- {
- }
- /**
- * The logout action.
- *
- * @access public
- * @return void
- */
- public function action_logout()
- {
- \Auth::logout();
- //Response::redirect('admin');
- \Response::redirect('/');
- }
- /**
- * The index action.
- *
- * @access public
- * @return void
- */
- public function action_index()
- {
- $this->template->title = 'Dashboard';
- $this->template->content = \View::forge('admin/dashboard');
- }
- }
- /* End of file admin.php */
Advertisement
Add Comment
Please, Sign In to add comment