Права Yii :: Ошибка 403 У вас нет прав на выполнение этого действия

Я новичок в yii. Я установил yii-rights в protected/modules/rights в соответствии с документацией. Но не может использовать должным образом. Что-то пропало, чего я не мог найти. страница localhost/index.php/right работает хорошо. Но когда я нажимаю на "разрешения", "роли", "задачи", "операции". Это показывает

«Ошибка 403. У вас нет прав для выполнения этого действия».

Вот мой основной конфиг::

'import'=>array(
 'application.modules.right.*',
 'application.modules.right.models*',
 'application.modules.rights.components.*',
 ),
'rights'=>array(

 'superuserName'=>'Admin', // Name of the role with super user privileges.
 'authenticatedName'=>'Authenticated', // Name of the authenticated user role.
 'userIdColumn'=>'id', // Name of the user id column in the database.
 'userNameColumn'=>'username', // Name of the user name column in the database.
 'enableBizRule'=>true, // Whether to enable authorization item business rules.
 'enableBizRuleData'=>false, // Whether to enable data for business rules.
 'displayDescription'=>true, // Whether to use item description instead of name.
 'flashSuccessKey'=>'RightsSuccess', // Key to use for setting success flash messages.
 'flashErrorKey'=>'RightsError', // Key to use for setting error flash messages.

 'baseUrl'=>'/rights', // Base URL for Rights. Change if module is nested.
  'layout'=>'rights.views.layouts.main', // Layout to use for displaying Rights.
  'appLayout'=>'application.views.layouts.main', // Application layout.
  'cssFile'=>'rights.css', // Style sheet file to use for Rights.
 'install'=>false, // Whether to enable installer.
'debug'=>false,
),
'components'=>array(
  'user'=>array(
  'class'=>'RWebUser',
   // enable cookie-based authentication
  'allowAutoLogin'=>true,
  'loginUrl'=>array('/user/login'),

 ),

Контроллер назначения

public function accessRules()
{
    return array(
        array('allow', // Allow superusers to access Rights

                        'actions'=>array(
                'view',
                'user',
                'revoke',
            ),
            'users'=>$this->_authorizer->getSuperusers(),
        ),
        array('deny', // Deny all users
            'users'=>array('*'),
        ),
    );
}

Мне нужна ваша помощь. ПОЖАЛУЙСТА

Обратите внимание: я также использую yii-user. yii-пользователь работает хорошо.


person Selim Reza    schedule 01.12.2013    source источник


Ответы (3)


В вашем контроллере вы должны назвать свое действие для выполнения функции.

  public function accessRules(){
    .......   
    array('allow', // allow authenticated user to perform 'create' and 'update' actions
                    'actions'=>array('create','update','districts','center'),
                    'users'=>array('@'),
    ......
    }

Например, в приведенном выше коде район и центр являются действиями.
Надеюсь, вы уловили идею.

person Femme Fatale    schedule 01.12.2013
comment
Это не работает ::: мой контроллер:: 'actions'=›array('view','user','revoke',), 'users'=›$this-›_authorizer-›getSuperusers(), - person Selim Reza; 01.12.2013
comment
пожалуйста, помогите мне с правильным решением. мне не удалось это исправить - person Selim Reza; 01.12.2013

Я знаю, что это старый вопрос, но вы добавили

public function filters()
{
    return array(
        'accessControl',
    );
}

к AssignmentController? Yii нужно учитывать функцию accessRules() для управления доступом.

person devOp    schedule 01.04.2014

Установите свой "Yii::app()->user->name";

Попробуй это

<?php
class UserIdentity extends CUserIdentity 
{
protected $_id;
const USER_INACTIVE = 3;

public function authenticate() 
{
    $p= Person::model()->findByUsername($this->username);
    if (empty($p))
        $this->errorCode = self::ERROR_USERNAME_INVALID;
    elseif (!CPasswordHelper::verifyPassword($this->password, $p->password))
        $this->errorCode = self::ERROR_PASSWORD_INVALID;
    else
    {
        $this->_id = $p->id;
        $this->username = $p->username;

        $this->errorCode = self::ERROR_NONE;
    }
    return !$this->errorCode;
}

public function getId() {
    return $this->_id;
}

}

строка "$this->username = $p->username;";

Надеюсь, это поможет.

person mvofreire    schedule 30.01.2015