Я пытаюсь изучить RBAC после различных онлайн-уроков и документов по yii и, наконец, заканчивается чем-то вроде ниже, я что-то пропустил, но я не знаю, что. Я дважды изучал теорию и учебные пособия, но все же усложняюсь с практической реализацией, поэтому, наконец, я решил обратиться за помощью к сообществу SO. то, что я сделал до сих пор точно нижеУдачи с RBAC в yii
**I step**
create a table with fields: username,password,email,role
role is enum datatype with 4 roles values ('superadmin','admin','useractive','userpassive')
**II step**
then i imported the schema-mysql.sql file in my database from the framework/web/auth folder of my yii setup.
**III step**
configured my config.php for CDbauthmanager
'authManager'=>array(
'class'=>'CDbAuthManager',
'connectionID'=>'db',
'itemTable'=>'AuthItem',
'itemChildTable'=>'AuthItemChild',
'assignmentTable'=>'AuthAssignment',
),
**IV step**
then i added few lines to UserIdentity.php
public function authenticate()
{
$user = Users::model()->findByAttributes(array('email'=>$this->username));
if ($user===null) { // No user found!
$this->errorCode=self::ERROR_USERNAME_INVALID;
}
else if ($user->password !== $this->password)
{ // Invalid password!
$this->errorCode=self::ERROR_PASSWORD_INVALID;
} else { // Okay!
$this->errorCode=self::ERROR_NONE;
// Store the role in a session:
$this->setState('roles', $user->role);
$this->_id = $user->id;
}
return !$this->errorCode;
}
public function getId()
{
return $this->_id;
}
**V step**
then i inserted values manually in the RBAC required table i.e. AuthItem,AuthItemChild,AuthAssignment
AuthItem table values
================================================================
name type description bizrule data
user1 2 the user1 role NULL NULL
updateProfile 0 update profile NULL NULL
================================================================
AuthItemChild
================================================================
parent child
user1 updateProfile
================================================================
AuthAssignment table values
================================================================
itemname userid bizrule data
user1 1 NULL NULL
And My users table
=================================================================
username password email role
test1 pass1 [email protected] user1
**VI step**
after that i tried to play with a controller
public function actionIndex()
{
if(Yii::app()->user->checkAccess('updateProfile'))
{
echo "yes";
}
else
{
echo "missing something";
}
}
теперь, когда я каротажного и пытается получить доступ к контроллеру с user1
это показать «что-то отсутствует», но у меня есть назначить пользователю ту же роль. Какого черта я пропал без вести.
Это то, что я сделал именно то, что мне не хватает, я не знаю, что я вряд ли могу это сделать.
Спасибо всем за ваше драгоценное время