简体   繁体   English

Yii用户权限扩展

[英]Yii user rights extension

i have installed the yii rights extension and here is my code after installation, database tables are created after installation. 我已经安装了yii版权扩展,这是安装后的代码,安装后会创建数据库表。

'modules'=>array(
        // uncomment the following to enable the Gii tool

            '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.    '
                          // Key to use for setting success flash messages.  
                            'flashErrorKey'=>'RightsError',  
                            / Key to use for setting error flash messages.    
                          //  'install'=>true,    // Whether to install rights.    
                            '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,
                    ),


        'gii'=>array(
            'class'=>'system.gii.GiiModule',
            'password'=>'1234',
            // If removed, Gii defaults to localhost only. Edit carefully to taste.
            'ipFilters'=>array('127.0.0.1','::1'),
        ),

    ),

But when i type url http://localhost/rightsTest/index.php/rights then it says 但是当我输入url http://localhost/rightsTest/index.php/rights然后它说

Error 403
There must be at least one superuser!

I have tried many things but unable to find answer. 我尝试过很多东西,却无法找到答案。 Thanks for your help. 谢谢你的帮助。

Do you have a user table with id, username fileds and you must check if there is atleast one record in that table. 你有一个id,用户名为fileds的用户表,你必须检查该表中是否有至少一条记录。 Because rights choose the first record in the user table as the Admin role. 因为权限选择用户表中的第一条记录作为Admin角色。

Create new admin user. 创建新的管理员用户。 There is one "user" table in database which is of rights moudle, make entry of your admin user with "username", "password" of your choice and dont forget to set "superuser" and "status" field values to 1.... 数据库中有一个“用户”表是权利模块,使用您选择的“用户名”,“密码”输入您的管理员用户,不要忘记将“超级用户”和“状态”字段值设置为1。 ..

You haven't specify the super user in config file. 您尚未在配置文件中指定超级用户。

  1. Open protected->config->main.php file in your yii installation. 在yii安装中打开protected-> config-> main.php文件。
  2. Find following piece of lines related to Rights configurations. 查找以下与权限配置相关的行。

      'rights'=>array( 'install'=>false, // Enables the installer. 'userNameColumn'=>'user_name', 'userClass'=>'Users', 'superuserName'=>'your_superuser_username' ), 
  3. Enter your superuser username as the value of 'superuserName'. 输入您的超级用户用户作为'superuserName'的值。

  4. Save main.php 保存main.php

and try to reload rights. 并尝试重新加载权利。 Problem will be solved. 问题将得到解决。 :) :)

NB: make sure your User Class and user_name column of your user table is also specified here correctly. 注意:确保您的用户表的User Class和user_name列也在此处正确指定。 Otherwise you may face to another issue. 否则你可能面临另一个问题。 Happy coding! 快乐的编码! Thanks. 谢谢。

I have same Problem, and i add my superuser name in RAuthorizer. 我有同样的问题,我在RAuthorizer中添加我的超级用户名。 in rights/component/RAuthorizer 在权利/组件/ RAuthorizer

$superusers = array('beautiful'); // Beautiful is my superadmin username
foreach( $users as $user )
$superusers[] = $user->name;

    if( $superusers===array() )
    throw new CHttpException(403, Rights::t('core', 'There must be at least one superuser!'));
    return $superusers;

And it works. 它有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM