2016-04-04 11 views
0

私はこの結果を得ようとしています - >管理者とスーパー管理者という2つのユーザータイプに対してアクセス制御ロジックを使用します。adminとsuper_adminのロールベースアクセス制御システム

管理者はシステム内のすべてのレコードに対して読み取りアクセス権を持ちますが、作成されたレコードのみに対して編集/削除アクセス権を持ちます。

スーパー管理者は、すべてのレコードに対して読み取り/編集/削除アクセス権を持ちます。この場合、私は何を使うべきですか?もし誰かが上記のケースで簡単な方法でコントロールにアクセスしてロールバックする方法を知っているなら、これを行う方法を教えてください。

私のページをadmin_login.phpからのログインがここに来た後... これは私のコントローラのページ..です

<?php 
defined('BASEPATH') OR exit('No direct script access allowed'); 

class Listing extends CI_Controller { 


public function __construct() 
{ 
    parent::__construct(); 
    $this->load->model('student'); 
    $this->load->helper('url'); 
    $this->load->helper('form'); 
    $s = $this->session->userdata('admin_id'); 
    log_message('error', 'Some variable did not contain a value.'); 
} 
public function index() 
{ 
    $s = $this->session->userdata('admin_id'); 

    $this->load->model('student',$s); 
    //$data['result'] = $this->student->listing(); 
    $students = $this->student->listing();/////new line delete [resulet]time 5:42 29/03/16 
    //$this->load->view('list_view',$data); //// change here time 5:52 29/03/16 
    $this->load->view('list_view',array('students'=>$students)); /////listing->list_view name change 
} 
public function delete($id) 
{ 

    $result = $this->student->delete_operation($id); 
    $s = $this->session->userdata('admin_id');// session data call. 
    //$data['result'] = $this->student->listing(); 
    $students = $this->student->listing();///new line 30/03 1230pm// change for list_view 
    $this->load->view('list_view',array('students'=>$students));///same as above//change for list_view 
    //$this->load->view('list_view',$data); ////////////////////////listing->list_view name change 
} 

public function edit($id) 
{    


    if($id) 
    { 
     $s = $this->session->userdata('admin_id'); 
     $result = $this->student->edit_record($id); 
     $data['action'] = 'edit'; 
     $data['student_id'] = $result[0]->student_id; 
     $data['student_name'] = $result[0]->student_name; 
     $data['student_email'] = $result[0]->student_email; 
     $data['student_address'] = $result[0]->student_address; 
     $data['subject'] = $result[0]->subject; 
     $data['marks'] = $result[0]->marks; 

    } 

    $this->load->view('edit_student',$data); 
} 
public function add_student() 
{  
    //$s['user'] = $this->session->userdata('admin_id');//get session data // new line30/03/16 
    $data['student_id'] = ''; 
    $data['student_name'] = ''; 
    $data['student_email'] = ''; 
    $data['student_address'] =''; 
    $data['subject'] = ''; 
    $data['marks'] = ''; 
    //$data['admin_id']=''; //new line 12:39 30/03/16 
    $this->load->view('edit_student',$data);   
} 

public function add() 
{ 
    $data = array(
    'student_name' => $this->input->post('txt_name'), 
    'student_email' => $this->input->post('txt_email'),   
    'student_address' => $this->input->post('txt_address'), 
    'subject' => $this->input->post('subject'), 
    'marks' => $this->input->post('marks'), 
    'admin_id' => $this->input->post('admin_id')//new line 12:39 31/03 
    ); 
    $result = $this->student->add_record($id,$data); 
    header('location:'.base_url().'index.php/listing'); 
} 


} 

答えて

0

listing.php

おそらく最良の方法は、いくつかの役割を使用することですお使いのシステムは、例えば、あなたはイオン認証ライブラリを使用することができます:あなたがユーザグループを定義することができますこれにより
http://benedmunds.com/ion_auth/

を(例えば:ユーザー、管理者、スーパーアドミニストレータ) マニュアルのin_group()の部分を調べて、その動作を確認することができます。

function hasDeleteRight($record_author_id, $logged_in_user_id) { 
    // if the user has administrator role we check if he is the author of the record he can delete it 
    if ($this->ion_auth->in_group('administrator', $logged_in_user_id)) { 
     if($record_author_id == $logged_in_user_id) { 
      return true; 
     } 
    // if the user has superadministrator role he anyway can delete the record 
    } elseif ($this->ion_auth->in_group('superadministrator', $logged_in_user_id)) { 
     return true; 
    } 
    // other users cannot delete the record 
    return false; 
} 

あなたはまだ機能のベースとしてこの例を使用することができます。
例の機能を使用すると、レコード削除を確認することができますどのようにいくつかのアイデアを取得してみましょうします。あなたのコード内

用法:

public function delete($id) 
{ 
    $logged_user_id = $this->session->userdata('admin_id'); 
    if(!hasDeleteRight($id, $logged_user_id)) 
    { 
     return false; 
    } 
    //....your delete record code 

更新:
だけセッションデータと分離されたログインでイオン認証なしでアクセス許可のチェック、(好ましくはない方法):スーパー管理者のログインコードで
ます

function super_admin_login() { 
    //your log in code 
    if($login_success) { 
     $this->session->set_userdata('permission', 'superadministrator'); 
    } 
} 

通常の管理者のログインに似ています:

function admin_login() { 
    //your log in code 
    if($login_success) { 
     $this->session->set_userdata('permission', 'administrator'); 
    } 
} 


function hasDeleteRight($record_author_id, $logged_in_user_id) { 
    // if the user has administrator role we check if he is the author of the record he can delete it 
    if ($this->session->userdata('permission') == 'administrator') { 
     if($record_author_id == $logged_in_user_id) { 
      return true; 
     } 
    // if the user has superadministrator role he anyway can delete the record 
    } elseif ($this->session->userdata('permission') == 'superadministrator') { 
     return true; 
    } 
    // other users cannot delete the record 
    return false; 
} 
+0

hello @zaragoli正式なライブラリなしでこれを行うことはできますか? –

+0

私はsession_dataで完了したいだけです –

+0

「admin_id」に基づいて管理者ユーザーを変更することができます。どのようなユーザーがスーパー管理者権限を持っているのですか?私はあなたのコードでそれが表示されません。 – Zaragoli

関連する問題