0

RBAC に CPHPAuthmanager を使用しています。コードのどこが間違っているのかわからない? 誰かがログインするたびに通常以外の役割を割り当てないのはなぜですか?

//保護された/config/app.php

<?php
  return array(
'userTypes' => array(
    'normal' => 0,
    'admin' => 1,
    'student' => 2,
    'teacher' => 3

),
'userTypesArray' => array(
    0 => 'normal',
    1 => 'admin',
    2 => 'student',
    3 => 'teacher'
),
    );
?>

//保護された/データ/auth.php

<?php
  return array(
'admin' => array(
        'type' => 2,
        'description' => '',
        'bizRule' => NULL,
        'data' => NULL
    ),

'student' => array(
        'type' => 2,
        'description' => '',
        'bizRule' => NULL,
        'data' => NULL
    ),

'teacher' => array(
        'type' => 2,
        'description' => '',
        'bizRule' => NULL,
        'data' => NULL
    ),

'normal' => array(
        'type' => 2,
        'description' => '',
        'bizRule' => NULL,
        'data' => NULL
    )
 );

?>

//保護された/コンポーネント/UserIdentity.php

if(count($users) == 0)
        $this->errorCode=self::ERROR_USERNAME_INVALID;
    elseif ($users[0]->password!==$this->password)
        $this->errorCode=self::ERROR_PASSWORD_INVALID;
    else
    {
        Yii::app()->authManager->clearAuthAssignments();
        $this->errorCode=self::ERROR_NONE;
        $this->setState('rol', $users[0]->type);
        if($users[0]->type == Yii::app()->params['app']['userTypes']['admin'])
            Yii::app()->authManager->assign('admin', $users[0]->UId);
        elseif($users[0]->type == Yii::app()->params['app']['userTypes']['student'])
            Yii::app()->authManager->assign('student', $users[0]->UId);
        elseif($users[0]->type == Yii::app()->params['app']['userTypes']['teacher'])
            Yii::app()->authManager->assign('teacher', $users[0]->UId);
        else
        {
            Yii::app()->authManager->assign('normal', $users[0]->UId);
        }
        Yii::app()->authManager->save();
    }
    return !$this->errorCode;

// 構成/メイン

$auth=Yii::app()->authManager;

$bizRule='return !Yii::app()->user->isGuest;';

$auth->createRole('normal', 'Normal User', $bizRule);

$bizRule='return (isset(Yii::app()->user->rol))? (Yii::app()->user->rol === "admin") : false;';
$auth->createRole('admin', 'System Admin', $bizRule);

$bizRule='return (isset(Yii::app()->user->rol))? (Yii::app()->user->rol === "student") : false;';
$auth->createRole('student', 'Student', $bizRule);

$bizRule='return (isset(Yii::app()->user->rol))? (Yii::app()->user->rol === "teacher") : false;';
$auth->createRole('teacher', 'Teacher', $bizRule);

//controllers/somecontroller

public function accessRules()
{
return array(
            array('allow', 
            'actions'=>array('index', 'view', 'create', 'update', 'admin','delete'),
            'roles'=>array('admin'),
        ),
        array('deny',  // deny all users
            'users'=>array('*'),
        ),
    );
}

助けてください、事前に感謝します。:)

4

1 に答える 1