[Extension] Auth

Hello chris!

Many Thanks For Your auth Module. This Is Very Useful. But There is a great lack :(

I Need To Use bizRule! I add bizRule Manualy To DataBase. I had to manually do it. But it does not work!

bizRule need $params parameters But There is no solution for it here.


if ($user->checkAccess($itemName, $this->params)) 

When This Code Execute In “AuthFilter” second parameters of checkAccess is empty! :(

How do I find the Appropriate object and put That Into $params array?

I have an app with several modules. Each module has its own controllers. I tried using setting up operations using


moduleId.*

but users assigned that operation are still denied access. If I use


moduleId/controllerId.*

no such issues arise. Do I have to create operations for all the controllers?

I guess, for example:




'modules' => array(

        ...

        'auth' => array(

            ...

            'appLayout' => 'application.views.layouts.main', // the layout used by the module.

        ),

...

You need change in config appLayout to defaultLayout




        'auth' => array(

            'strictMode' => true,

            'userClass' => 'Users',

            'defaultLayout' => 'application.views.layouts.main',

            'viewDir' => 'application.modules.auth.views',

            'forceCopyAssets' => true,

        ),



To answer everyone who’s asking about the business rules, the reason why they are not include is because I don’t think that such data belongs in the user interface. I’ve been thinking about writing a console command for setting business rules but I’m afraid that it’s still on an idea level. I’ll see what I can do when I have time to work on this project. Right now I’m kind of busy as my second son was born earlier this week.

I recently added support for moduleId.*, try upgrading and report back. I hope this resolves your issue.

what a pleasure! I wish you the bests for the little new man! :D

yii-auth not properly shown up with tab…i think the nav widget cant handle it?

Hey Chris,

Thanks for the extension! One thing I’m finding frustrating though…

Why force everyone to use bootstrap?

Wouldn’t the extension be more widely useful if using bootstrap were optional?

I mean, bootstrap looks great, but it seems to me that most developers would like to have their choice of front-end.

Since I’m not using bootstrap elsewhere, I have to install it for this functionality only. And then the auth management interface is not consistent with the rest of my app…

You’re not forced to use bootstrap, just write your own views and you can use whatever you want. You can configure the views folder for the module.

Hey Chris,

i have downloaded yii-auth-1.6.0.zip version of this extension. and done configuration as you have mentioned here.

But when i am trying to access the application i am getting below given exception.

"Property "AuthWebUser.admins" is not defined. "

Any thoughts about it.

Then i temporary commented below given code.

‘user’ => array(

      'class' => 'auth.components.AuthWebUser',


      //'admins' => array('admin', 'foo', 'bar'), // users with full access


    ),

And run the app. now its working.

But i am unable to access the magic of this extension yet.Its showing permission error.

Could you please tell me how could i fix it.

And also. in you downloaded extension AuthModule.php is not updated as it is shown here

Could you please confirm it.i guess latest release of this extension have still some bugs.Any quick response would be great for us.

Looking forward to here from you.

Thanks in Advance.

it’s not good. you have to solve this issue. something is not okay with your installation I guess. the extension has to work with ‘admins’ option enabled.

exactly what page you want to see and exactly what error message do you get? without these informations it’s impossible to help.

Hi first of all, thanks for the extension. It’s really useful, although I dont know how to set owner validation into the yii-auth logic

I always use the below code of validation, it’s not a good piece of code because it does not allow the separation of cross-cutting logic.





actionUpdate($id){

$post_model=$this->loadmodel($id);

if($post_model->user_id==Yii::app()->user->getId())

 #do st..

else

 #shame on you

}




please, What is the best way to fulfill my expectations? thanks SERGIO

Thanks for your reply.

Well i am trying to access /auth/assignment/index this page.then i am getting permission error. And when i am enable admins then it is throwing me Webuser Exception.

I hope it is a bit clear to you.

i Know that admins should be enable to access this extension.But its throwing me exception for Webuser module error.Which i need to fix.

paste exact error message or printscreen here.

[b]

Error 401

Access denied.

[/b]

This error i am getting here.When i was trying to access /auth/assignment/index this page.

And if i uncomment


'user' => array( 'class' => 'auth.components.AuthWebUser', //'admins' => array('admin', 'foo', 'bar'), // users with full access ),

admins there then it is throwing Property "AuthWebUser.admins" is not defined. Exception.

Check attached screenshot for it.

4111

CException 2013-04-12 09-41-32.png

codesutra, I have the same error now. Can’t see what’s wrong.

My main.php


<?php

// uncomment the following to define a path alias

// Yii::setPathOfAlias('local','path/to/local-folder');

// Define a path alias for the Bootstrap extension as it's used internally.

// In this example we assume that you unzipped the extension under protected/extensions.

Yii::setPathOfAlias('bootstrap', dirname(__FILE__).'/../extensions/bootstrap');


// This is the main Web application configuration. Any writable

// CWebApplication properties can be configured here.

return array(

	'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',

	'name'=>'Yii Auth Demo',

	

    'theme'=>'bootstrap', // requires you to copy the theme under your themes directory 


	// preloading 'log' component

	'preload'=>array('log'),

    

	'modules' => array(

	    'auth'=>array(

			'appLayout' => 'webroot.themes.theme.views.layouts.main', // the layout used by the module.

		),

		'gii'=>array(

            'generatorPaths'=>array(

                'bootstrap.gii',

            ),

        ),

	),


	// autoloading model and component classes

	'import'=>array(

		'application.models.*',

		'application.components.*',

	),


	'defaultController'=>'post',


	// application components

	'components'=>array( 

		'bootstrap'=>array(

            'class'=>'bootstrap.components.Bootstrap',

        ),

		'authManager' => array(

			'class'=>'CDbAuthManager',

		  	//'connectionID' => 'db',

			'behaviors' => array(

	        	'auth' => array(

	          		'class' => 'auth.components.AuthBehavior',

					'admins'=>array('admin','demo','authenticated'), // users with full access

	        	),

			),

	    ),

	    'user'=>array(  

			'class' => 'auth.components.AuthWebUser',

			'admins' => array('admin','demo','authenticated'), // users with full access

			// enable cookie-based authentication

			//'allowAutoLogin'=>true,

		),

		/*'db'=>array(

			'connectionString' => 'sqlite:protected/data/blog.db',

			'tablePrefix' => 'tbl_',

		),*/

		// uncomment the following to use a MySQL database

		

		'db'=>array(

			'connectionString' => 'mysql:host=localhost;dbname=yii-auth',

			'emulatePrepare' => true,

			'username' => 'root',

			'password' => 'root',

			'charset' => 'utf8',

			'tablePrefix' => '',

		),

		

		'errorHandler'=>array(

			// use 'site/error' action to display errors

			'errorAction'=>'site/error',

		),

		'urlManager'=>array(

			'urlFormat'=>'path',

			'rules'=>array(

				'post/<id:\d+>/<title:.*?>'=>'post/view',

				'posts/<tag:.*?>'=>'post/index',

				'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

			),

		),

		'log'=>array(

			'class'=>'CLogRouter',

			'routes'=>array(

				array(

					'class'=>'CFileLogRoute',

					'levels'=>'error, warning',

				),

				// uncomment the following to show log messages on web pages

				/*

				array(

					'class'=>'CWebLogRoute',

				),

				*/

			),

		),

	),


	// application-level parameters that can be accessed

	// using Yii::app()->params['paramName']

	'params'=>require(dirname(__FILE__).'/params.php'),

);

UserIdentity.php


<?php


/**

 * UserIdentity represents the data needed to identity a user.

 * It contains the authentication method that checks if the provided

 * data can identity the user.

 */

class UserIdentity extends CUserIdentity

{

    private $_id;


    /**

     * Authenticates a user.

     * @return boolean whether authentication succeeds.

     */

    public function authenticate()

    {

        /* @var $user User */

        $user = User::model()->find('LOWER(username)=?', array(strtolower($this->username)));

        if ($user === null)

            $this->errorCode = self::ERROR_USERNAME_INVALID;

        else if (!$user->validatePassword($this->password))

            $this->errorCode = self::ERROR_PASSWORD_INVALID;

        else

        {

            $this->_id = $user->id;

            $this->username = $user->username;

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

			if(!is_null($user->role)){

			    if(!$auth->isAssigned($user->role,$this->_id))

			    {

			        if($auth->assign($user->role,$this->_id))

			        {

			            Yii::app()->authManager->save();

			        }


			    }

			}

            $this->errorCode = self::ERROR_NONE;

        }


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

    }


    /**

     * @return integer the ID of the user record

     */

    public function getId()

    {

        return $this->_id;

    }

}

I use database, storing authitems and others…

And another different error, after login (if i use dev version from github):

Property "AuthBehavior.admins" is not defined

it occur both with CPhpAuthManager or CDbAuthManager.

i found that it causes by


'authManager' => array(

			'class'=>'CDbAuthManager', 

			'behaviors' => array(

	        	'auth' => array(

	          		'class' => 'auth.components.AuthBehavior',

					'admins'=>array('authenticated'), // users with full access

	        	),

			),

	    ), 

well, as I see, in my config file there are additional settings for auth, for example in modules section:




'modules' => array(

        'auth' => array(

            'strictMode' => true, // when enabled authorization items cannot be assigned children of the same type.

            'userClass' => 'Users', // the name of the user model class.

            'userIdColumn' => 'id', // the name of the user id column.

            'userNameColumn' => 'username', // the name of the user name column.

            'appLayout' => 'application.views.layouts.main', // the layout used by the module.

            'viewDir' => null, // the path to view files to use with this module.

        ),

        'user' => array(

            'tableUsers' => 'users',

            'tableProfiles' => 'profiles',

            'tableProfileFields' => 'profiles_fields',

        ),



and also this one:




'import' => array(

        'application.models.*',

        'application.components.*',

        'application.modules.user.models.*',

        'application.modules.user.components.*',

        'application.modules.auth.*',

        'application.modules.auth.components.*',

        ...

    ),



do you also have these settings?

Thanks cappadochian for your quick responses. But finally i manage to resolve all that errors :)

thanks again. :)