[Module] Yii User Management Module

This is the forum thread for the Yii User Management Module

In order to use this Module, please be sure to use the latest development Snapshot of yii or at least yii-1.1.1 (to be released).

It will not work with the stable yii-1.1. (Only with a few Workarounds)

I have just released this Tutorial for installing the User Management Module under a fresh installed Skeleton Application generated by yiic.

Cookbook Page for a Tutorial of installing Yii-User-Management under a fresh Application skeleton (68)

Please test my freshly released Version 0.2 of this Module and give me all sort of feedback

(Bug Reports, Feature Requests, and so on)

many thanks to the yii-user Module which was the codebase for this Module. As far as i know it gets developed in parallel to this

Module. We should modularize and merge our features soon.

Also take a look at grbac !

last but not least: enjoi!

found a bug for version 0.2 after fixing "public $menu=array();".

the insert statement in line 136 is missing fields for "about" and "street". They were set as NOT NULL in the create statement

bug is fixed in svn. svn and issue tracker is available here:

http://code.google.com/p/yii-user-management/

Updated to the latest svn and it’s looking good :)

In your walkthrough, along with the change to the ‘login’ link, you might also want to change the logout link in /views/layouts/main.php but it works regardless.

Great extension.

Edit:

In /modules/views/layouts/column2.php I added the following to prevent the display of the empty ‘operations’ menu header when not logged in.


if (!Yii::app()->user->isGuest) {

    $this->beginWidget('zii.widgets.CPortlet', array(

    ....

}

I’m a newbie to Yii. I have a simple app up and running, just pulling data from one table right now. I followed the steps for this UMM, but the /user/install doesn’t seem to do anything, so I can’t actually do the install process. Basically, i put the URL in and get no response, although the rest of my site works. ANy idea how I debug this? I really want to check out this extension!

To clarify quickly, if I go to the URL http://localhost/yii/MyApp/index.php/user/install it takes me to the standard Yii app home page…

Please try http://localhost/yii/MyApp/index.php/user/user/install

(ModuleID/ControllerID/actionID).

Please take a look in your protected/config/main.php. Activate your Url Manager by removing the Comments at

// uncomment the following to enable URLs in path-format

this enables to use index.php/user/install instead of index.php?r=user/install

i think this will become the default in the near future, so i didn’t wrote this step in my tutorial.

the route ‘user/install’ already calls the user-module. Install is the action of the default Controller. This is why you don’t need to use user/user/install. But you can, if you want.

all other bugs have been collected and will be fixed in the next version.

i will also implement a ‘who has watched your profile’ and a ‘profile guestbook’ where guestbook entries can be moderated by the profile owner in the next version.

If anyone wants to contribute to this project with some submodules or something, i can give access to the svn repository to everyone interested. Thank you.

Hmmm. I tried this URL also (http://localhost/yii/MyApp/index.php?r=user/install) and it still doesn’t launch the install page. Does the install just setup the DB tables? If so, do you have a SQL script I could try instead?

probably your config

If you can post it I’ll have a quick look

i think standard shell created yii app has NO url-manager in default. so one has to add to main.php config file this (in components section):




'urlManager'=>array(

    'urlFormat'=>'path',

),



now the http://localhost/yourapp/index.php/user/install works fine

I’ve tried a few of these suggestions. I still can’t get /user/user/install to work, so have been using index.php?r=user/user/install. I think I am getting closer; the page now reads ‘The system is unable to find the requested action “install”.’

My config.php looks like this. Any suggestions warmly welcomed!

<?php

// uncomment the following to define a path alias

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

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

// CWebApplication properties can be configured here.

return array(

'basePath'=&gt;dirname(__FILE__).DIRECTORY_SEPARATOR.'..',


'name'=&gt;'JPIM',





// preloading 'log' component


'preload'=&gt;array('log'),





// autoloading model and component classes


'import'=&gt;array(


	'application.models.*',


	'application.components.*',


),





// application components


'components'=&gt;array(





	'user'=&gt;array(


		// enable cookie-based authentication


		'allowAutoLogin'=&gt;true,


		'loginUrl' =&gt; array('user/user/login'),


	),

/* JSH: Added code to use User module for security */

	'User'=&gt;array(


		'class' =&gt; 'User',


	),


    /*


	'db'=&gt;array(


		'connectionString' =&gt; 'sqlite:protected/data/testdrive.db',  


	),


*/


	// uncomment the following to use a MySQL database		


	'db'=&gt;array(


		'connectionString' =&gt; 'mysql:host=192.168.1.98;dbname=xxxx;port=8889',


		'emulatePrepare' =&gt; true,


		'username' =&gt; 'xxxx',


		'password' =&gt; 'xxxx',


		'charset' =&gt; 'utf8',


	),		


	'errorHandler'=&gt;array(


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


        'errorAction'=&gt;'site/error',


    ),


	'log'=&gt;array(


		'class'=&gt;'CLogRouter',


		'routes'=&gt;array(


			array(


				'class'=&gt;'CFileLogRoute',


				'levels'=&gt;'error, warning',


			),


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


			/*


			array(


				'class'=&gt;'CWebLogRoute',


			),


			*/


		),


	),


),





// application-level parameters that can be accessed


// using Yii::app()-&gt;params['paramName']


'params'=&gt;array(


	// this is used in contact page


	'adminEmail'=&gt;'example@gmail.com',


),





'modules' =&gt; array(


		'user' =&gt; array(


  		'debug' =&gt; true)


	),





/* JSH this raises error: Property &quot;CWebApplication.urlManager&quot; is read only, so have commented this out&#33;


'urlManager' =&gt; array(


	'urlFormat'=&gt;'path',


),


*/

);

I am on Yii 1.1 stable. With few workaround I could install user management module. However, i had trouble to use it, in my application, I wrote a simple example like this

<?php if( Yii::app()->User->hasRole( ‘SALES’ ) ) { echo ‘Role is correct!’; } else { echo ‘ERROR!’; } ?>

It produced an error:

include(User.php) [<a href=‘function.include’>function.include</a>]: failed to open stream: No such file or directory

Anyone can help?

I also tried with Yii 1.1 dev, resulting in the same error message


include(User.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory

Should I also copy User.php from the module/user to model/ ? I only copy the UserIdentity from module/user to component/

This is very good module that I am looking for a long time…

Hi I set up up Yii User Management Module today and was able to get it installed but have some issues / question regarding usage…

I set up several roles, and when I went to update users there was a field that (I assumed…) you selected roles for that user. I highlighted the roles, hit save, and I get:

This User belongs to this roles:

None

So - for starters, does a user belong to a role, or can a user have several roles, and why doesn’t it update with my selections???

BTW, I thought your setup tutorial was excellent - maybe a usage tutorial along those same lines would help people once they get it installed…

I set up a directory and grabbed the snapshot just to try this and compare to SRBAC, which I have on a straight 1.1 setup. That was much harder to set up than your system, especially from the documentation standpoint. However, I have SRBAC functioning and don’t have this working - only installed - yet…

I think better below:


if (!empty($this->menu)) {

    $this->beginWidget('zii.widgets.CPortlet', array(

    ....

}

I recently had some Problems with the yii route generator, too. I am trying to fix these issues in the yii-user 0.3 which will be released soon and addresses many of the Problems reported by users (thank you)

The Addition to the column2.php has been added in svn

@Michael Sullivan:

This will be fixed in the yii-user0.3 version. User and Role indeed have MANY_MANY Relation. As a workaround just replace the relation ‘users’ in models/Roles.php from (user,role) to (role,user), so everything works. Or use my svn trunk/. Or wait for user0.3 :)

One can use the Google Code Issue tracker or, if someone wants to, can help develop this module. I like the Google Code SVN thing, and this module can grow large and stable with some more volunteer help.

@Daniel:

also fixed in svn. it’s Users rather than User - my mistake ;)

Thanks for the reply thyseus, but I do not quite understand which one should be changed to Users? Where can I get the code from SVN?

Once again, many thanks.

@Daniel:

Yii-User 0.3 gets released today. SVN is available here: http://code.google.com/p/yii-user-management/

I have fixed the whole Role-Check routine. Now one can use this syntax:




if(User::hasRole('role'))

{

 // user is allowed

}

else

{

 // user is not allowed to do this

}



When Updating to 0.3 please make sure to copy over the components/Useridentity.php again, since there was important code changed (or reinstall to make sure everything works)

It’s important to add this line to your application configuration:




 'import'=>array(  

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



i have updated the Cookbook Page and the Documentation included with the yii-user package under docs/

I hope that this will now work for you!!

If anyone has a better idea on how the Access of the actual User can be checked, please give me an hint. Further polishing of messages are already in svn onwards to 0.4. I’m interested in a high quality module ;) Anyone wants to translate messages in yii-user-management?

@jherstein:

i would like to know if the route problems are solved in user0.3. Please always use the latest yii1.1-dev.

Yii User 0.4 is released.

Changelog:

  • One can use User::hasRole(array(‘role1’, ‘role2’)) to check if the User belongs to role 1 OR role 2 (thyseus)

  • Rearranged Menu Items more logical (thyseus)

  • Much more strict OOP Design (thyseus)

  • UserIdentity.php no longer needs to be copied (zephca)

  • Created WebUser class to tie in the cookie based user management features to the DB. (zephca)

  • Fixed some references to unset objects (zephca)

  • Changed directory permissions to 755 and file permissions to 644 so it works better with Git source control (zephca)

  • User can log in by username, E-Mail or both depending on loginType (thyseus)

  • Added possibility to set up Roles in User form and Users in Role form (thyseus)