1

codeigniter2.1.3用にIonAuthをセットアップしました。

すべてがうまく機能しています。

私のコントローラーでは、auth.php関数index()の次のコードがあります。

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

ログインしていない人や正しいグループに属していない人がページにアクセスできないように、ビュー/コントローラーへのアクセスを制限するにはどうすればよいですか。

4

1 に答える 1

1

異なるビューをロードする代わりに、uは各ユーザーグループを異なるコントローラーにリダイレクトする必要があります。

認証インデックス

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を介した不要なメソッドの実行が防止されます。

于 2013-03-01T07:26:53.173 に答える