A user management module collection for the yii framework >= 1.1.14
Hint: For Yii2 i highly suggest the dektrium/yii2-user module: https://github.com/dektrium/yii2-user .
Starting from 0.9, a demo application is available here:
https://github.com/thyseus/yii-user-management-demo
php composer.phar require thyseus/yii-user-management
array(
'aliases' => array(
'vendor' => '/path/to/vendor',
),
),
The Yii User Management Module needs a mysql Database Connection to work.
Clone the package into your projects modules/ directory:
$ cd protected/modules
$ git clone https://github.com/thyseus/yii-user-management
The Yii-user-management module contains submodules that you just extracted into your application's modules/user directory. You can remove all submodules you do not need. Move the files one folder up so they are inside your modules/ folder:
$ mv user/* .
(optional: remove demo application)
$ rm -rf index.php composer.json hybridauth.php controllers views
$ [youreditor] protected/config/main.php
Add these lines:
'modules' => array(
'user' => array(
'debug' => true,
)
),
The debug option is needed for the installation and is helpful during development. It should be set to false when running in production.
'components'=>array(
'user'=>array(
'class' => 'application.modules.user.components.YumWebUser',
'allowAutoLogin'=>true,
'loginUrl' => array('//user/user/login'),
[...]
),
'import'=>array(
'application.modules.user.models.*',
[...]
This tells our Web Application that is can access the Model 'User' even when not in the modules/user environment. This is needed for calling User::hasRole($role) in your Code to check if the logged in User belongs to the role. This is explained in the detailed Documentation. It is good to let this line occur as the first included Model, so you can extend the User-Model with your own in your Application models/ Directory if you like.
'components' => array(
'cache' => array('class' => 'system.caching.CDummyCache'),
inside the components section of your config/main.php.
Also see http://www.yiiframework.com/doc/guide/1.1/en/caching.overview about some general information about caching in yii.
http://localhost/testdrive/index.php/user/install or http://localhost/testdrive/index.php?r=user/install
depending on your URL route setup.
Click 'Install Module'. After clicking it, the install script will create the database tables needed by the module(s). Then it will show you the neccesary modifications to be made. Add the Modules you need to your Application Configuration as provided by the install script in config/main.php. You can also remove the Yum modules you don't want to use.
Congratulations, you have installed the User Management Module! Lets tidy up a little bit:
Login as admin/admin and navigate to index.php?r=user/user/admin. This is your user management administration panel. Click on "Administrate your Users" Now you are taken to the default Front-End Login-Screen of the User Management Module. Log in with the Username admin and Password admin.
Click on the 'update Icon' (the pencil) of your administrator User. Change the Password to something more safe than 'admin'. Click Save.
If you didn't already, remove the 'debug' => 'true' line from your Application Configuration, so your new data can't get overwritten accidentally by the installation process.
The Yii-User Management Module uses the language that is set in the Application Configuration. For example, you can add a
'language' => 'de',
in your config/main.php to get German Language strings. At the moment English, German, French and Polish are supported.
If you want to display a quick login widget somewhere in your Web Application, just call in your view file:
<?php $this->widget('application.modules.user.components.LoginWidget'); ?>
You can setup the password Requirements within the 'passwordRequirements' option of the Module, for example:
'user' => array( 'passwordRequirements' => array( 'minLen' => 4, 'maxLen' => 16, 'maxRepetition' => 2, 'minDigits' => 3, ),
Please see components/CPasswordValidator.php for possible password requirement options
Set the Variable 'enableActivationConfirmation' to false in the module configuration to let users register for your application without needing to receive/click an emailed confirmation link.
You can add up new roles in the Role Manager. To check for access to this roles, you can use this code Snippet everywhere in your Yii Application. Most likely it will be used in the ACL Filter of your Controllers:
if(Yii::app()->user->can('action'))
{
// user is allowed
}
else
{
// user is not allowed to do this
}
Please see the file user/docs/logging.txt for information on how to set up the logging functions of the Yii User Management module.
There are some examples on how to extend from the Yii User Management Module and how to implement project-specific stuff. See the files in the user/docs/ directory for all this.
See user/docs/hybridauth.txt for instruction on how to use the wonderful hybrid auth framework that is bundled with yii-user-management.
Q: I get an exception when running the Installer
A: Please make sure to log out from any session. Clear your cookies to make sure you are not logged in in your Web Application anymore.
Q: I get the error Message: CWebUser does not have a method named "isAdmin":
A: Please make sure that you have the following in your application configuration:
'components'=>array(
'user'=>array(
'class' => 'application.modules.user.components.YumWebUser',
Q: I get the error Message: the table "{{users}}" for active record class "YumUser" cannot be found in the database.
A: Please make sure that you have the following in your application configuration:
'db'=>array(
'tablePrefix' => '',
[...]
Q: Why doesn´ t the yii-user-management have submodules?
A: Submodules are supported by yii, but having a path like application.modules.user.modules.role.controllers.YumRoleController really looks strange, so we decided it is better to keep all modules inside the root modules/ directory.
Q: I get the following error while installing: General error: 2014 Cannot execute queries while other unbuffered queries are active
A: thanks to NetDabbler, there is a workaround:
Comment the folowing lines in YumInstallController.php // $sql = file_get_contents(Yii::getPathOfAlias('application.modules.user.docs') . '/yum_translation.sql'); // $db->createCommand($sql)->execute();
Insert the translation data manually in a cmd window as: mysql -u yourusername -p testyum < docs/yum_translation.sql
Q: I still got errors !
A: Make sure to enable a caching component, at least CDummyCache, in your config/main.php:
'cache'=>array( 'class'=>'system.caching.CDummyCache', ),
Q: I still got errors !
A: Try to add this in your config/main.php:
'session' => array(
'sessionName' => 'SiteSession',
'class' => 'CHttpSession',
'autoStart' => true,
),
The documentation is stored in the user/docs directory. Please read user/docs/install.txt for a installation instruction.
Please DO read the documentation since it is not 100% trivial to install this module. There also is a FAQ of common mistakes at the end.
Report all issues to the github issue tracker, thank you!
Enjoy this module.