【问题标题】:Yii user rights extensionYii 用户权限扩展
【发布时间】:2015-05-05 14:27:23
【问题描述】:

我已经安装了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'),
        ),

    ),

但是当我输入 url http://localhost/rightsTest/index.php/rights 然后它说

Error 403
There must be at least one superuser!

我尝试了很多东西,但找不到答案。感谢您的帮助。

【问题讨论】:

  • 您是否检查了您指定为超级用户的帐户是否确实存在?也许在您的数据库中它被称为“admin”而不是“Admin”。
  • 我没听懂你,你说的是哪个数据库表?我认为它的这个扩展在数据库中创建了 4 个表。 Authassignment,authitem,authitemchild,权利。请问你说的是哪张桌子?
  • 好吧,你在某处有一个用户表——毕竟所有用户数据都必须从某处提取。我所说的就是那个信息来源。
  • 是的,我有一个用户表,我已经检查过了,同样的错误 403 发生了。
  • 顺便说一句,权限的创建者创建了另一个应用程序来处理比权限更少的错误和更灵活的授权:github.com/Crisu83/yii-auth

标签: php yii


【解决方案1】:

您是否有一个包含 id、用户名字段的用户表,并且您必须检查该表中是否至少有一条记录。因为权限选择用户表中的第一条记录作为管理员角色。

【讨论】:

    【解决方案2】:

    创建新的管理员用户。数据库中有一个“用户”表,它是权限模块,使用您选择的“用户名”、“密码”输入您的管理员用户,不要忘记将“超级用户”和“状态”字段值设置为 1.. ..

    【讨论】:

      【解决方案3】:

      您没有在配置文件中指定超级用户。

      1. 在你的 yii 安装中打开 protected->config->main.php 文件。
      2. 找到以下与权限配置相关的行。

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

      4. 保存main.php

      并尝试重新加载权限。问题将得到解决。 :)

      注意:请确保您的用户表的用户类和用户名列也在此处正确指定。否则你可能会面临另一个问题。快乐编码!谢谢。

      【讨论】:

        【解决方案4】:

        我有同样的问题,我在 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;
        

        而且它有效。

        【讨论】:

          猜你喜欢
          • 2014-09-01
          • 1970-01-01
          • 1970-01-01
          • 2014-08-27
          • 1970-01-01
          • 2012-05-05
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多