Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Controller_Admin extends Controller_Base {
- private $user_group_id = 1;
- private $admin_group_id = 100;
- public $template = 'admin/template';
- public function before() {
- parent::before();
- 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($this->admin_group_id)) {
- Session::set_flash('error', e('You don\'t have access to the admin panel'));
- Response::redirect('/');
- }
- if (Auth::member($this->user_group_id)) {
- Response::redirect('main');
- }
- }
- else {
- if (Auth::member($this->user_group_id)) {
- Response::redirect('member/login');
- }
- elseif (Auth::member($this->admin_group_id)) {
- Reponse::redirect('admin/login');
- }
- }
- }
- }
- public function action_login() {
- // Already logged in
- Auth::check() and Response::redirect('admin');
- $val = Validation::forge();
- if (Input::method() == 'POST') {
- $val->add('email', 'Email or Username')
- ->add_rule('required');
- $val->add('password', 'Password')
- ->add_rule('required');
- if ($val->run()) {
- $auth = Auth::instance();
- // 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
- 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');
- }
- }
- }
- $this->template->title = 'Login';
- $this->template->content = View::forge('admin/login', array('val' => $val), false);
- }
- /**
- * The logout action.
- *
- * @access public
- * @return void
- */
- public function action_logout() {
- Auth::logout();
- Response::redirect('main');
- }
- /**
- * The index action.
- *
- * @access public
- * @return void
- */
- public function action_index() {
- if (Auth::check()) {
- if (Auth::member($this->admin_group_id)) {
- $this->template->title = 'Dashboard';
- $this->template->user_type = 'admin';
- $this->template->content = View::forge('admin/dashboard');
- }
- else
- Response::redirect('member');
- }
- else
- Response::redirect('admin/login');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment