2013-02-26 3 views
1

codeigniter 2.1.3에 대해 Ion Auth를 설정했습니다.codeigniter 및 IonAuth로보기 고정

모두 잘 작동합니다. 나는 기능 지수()에 대한 아래의 코드를 auth.php 내 컨트롤러에서

:

function index() 
{ 
    // if not logged in - go to home page 
    if (!$this->ion_auth->logged_in()) 
    { 
     //redirect them to the login page 
     redirect('auth/login', 'refresh'); 
    } 
    // if user is an admin go to this page 
    elseif ($this->ion_auth->is_admin()) 
    { 
     echo "Admin User"; 
     // if an admin, go to admin area 

     //set the flash data error message if there is one 
     $this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message'); 

     //list the users 
     $this->data['users'] = $this->ion_auth->users()->result(); 
     foreach ($this->data['users'] as $k => $user) 
     { 
      $this->data['users'][$k]->groups = $this->ion_auth->get_users_groups($user->id)->result(); 
     } 

     $this->_render_page('auth/view_users', $this->data);     
    } 
    //if user is part of the master data team 
    elseif ($this->ion_auth->in_group("master_data")) 
    { 
     echo "master data group"; 
     //redirect them to the master_data page 
     $data['title']="Master Data Home Page"; 
     $this->load->view("site_header",$data); 
     $this->load->view("site_nav"); 
     $this->load->view("content_master_data"); 
     $this->load->view("site_footer"); 

    } 
    elseif ($this->ion_auth->in_group("planning")) 
    { 
     echo "Planning"; 
     //redirect them to the master_data page 
     $data['title']="IMS Planning"; 
     $this->load->view("site_header",$data); 
     $this->load->view("site_nav"); 
     $this->load->view("content_planning"); 
     $this->load->view("site_footer"); 

    } 
    else 
    { 
     echo "Generic user"; 
     //redirect them to the default home page 
     $data['title']="IMS Home Page"; 
     $this->load->view("site_header",$data); 
     $this->load->view("site_nav"); 
     $this->load->view("content_home"); 
     $this->load->view("site_footer"); 
    } 
} 

내 생각 프로세스가 사용자가 올바른 그룹에있는 경우 컨트롤러 만로드되는 것입니다. 이 올바르게 작동하고 각 사용자에 대해 올바른보기가로드됩니다. 내 문제는 어떤보기로든 직접 찾아 볼 수 있다는 것입니다. 예를 들어 http://localhost/logico/application/views/content_master_data.php

로그인하지 않은 사람과 방문하지 않은 사람이 페이지에 액세스 할 수 없게하려면보기/컨트롤러에 대한 액세스를 제한하려면 어떻게합니까? 올바른 그룹.

답변

1

다른보기를로드하는 대신 각 사용자 그룹을 다른 컨트롤러로 리디렉션해야합니다.

인증 색인

function index() 
{ 
    // if not logged in - go to home page 
    if (!$this->ion_auth->logged_in()) 
    { 
     //redirect them to the login page 
     redirect('auth/login', 'refresh'); 
    } 
    // if user is an admin go to this page 
    elseif ($this->ion_auth->is_admin()) 
    { 
     echo "Admin User"; 
     // if an admin, go to admin area 

     //set the flash data error message if there is one 
     $this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message'); 

     //list the users 
     $this->data['users'] = $this->ion_auth->users()->result(); 
     foreach ($this->data['users'] as $k => $user) 
     { 
      $this->data['users'][$k]->groups = $this->ion_auth->get_users_groups($user->id)->result(); 
     } 

     $this->_render_page('auth/view_users', $this->data);     
    } 
    //if user is part of the master data team 
    elseif ($this->ion_auth->in_group("master_data")) 
    {   
     //redirect them to the master controller 
     redirect('master','refresh');   

    } 
    elseif ($this->ion_auth->in_group("planning")) 
    { 
//redirect them to the planning controller 
     redirect('planning',refresh);   
    } 
    else 
    { 
//redirect them to the generic controller 
redirect('generic','refresh'); 

    } 
} 

마스터 컨트롤러

class Master extends CI_Controller { 

    function __construct() 
    { 
    parent::__construct(); 
    if (!$this->ion_auth->in_group('master_data')) 
    { 
       redirect('auth/login', 'refresh'); 
      } 
     } 
function index() 
{ 
      $data['title']="Master Data Home Page"; 
      $this->load->view("site_header",$data); 
      $this->load->view("site_nav"); 
      $this->load->view("content_master_data"); 
      $this->load->view("site_footer"); 
} 
} 

이와 비슷하게 계획 및 URL을 통해 원치 않는 메소드 실행을 방지 할 수 해당 인증 check.This을 포함해야 일반적인 컨트롤러의 생성자입니다.