useradmin

Complete module for managing users, they premissions, tasks and roles
20 followers

UserAdmin module

Helps manage users, they roles and allowed tasks.

Gitlab link

Screenshots


user list user task details user details


Requriements: Twitter bootstrap 2.+

Installation

1) Extract and place

Probably you have folder in lowercase useradmin. Change it to UserAdmin And place it in '/modules/'

2) Database

Import "UserAdmin/data/user_admin.sql"

3) Config file

...
'import'=>array(
        ...
        'application.modules.UserAdmin.components.*',
        'application.modules.UserAdmin.models.*',
        ...
),
...
'modules'=>array(
        ...
        'UserAdmin',
        ...
),
'components'=>array(
        ...
        'user'=>array(
                'class'=>'UWebUser',
                'allowAutoLogin'=>true,
                'loginUrl'=>array('/UserAdmin/auth/login'),
        ),
        ...
)
...

You can also set cache expiration time (default is 3600)

...
'modules'=>array(
       ...
       'UserAdmin' => array(
               'cache_time' => 3600,
       ),
       ...
),
...

4) Extending base Controller

Extend your base "Controller" with "UAccessController"

<?php
class Controller extends UAccessController
{
        ...
}

If you have filters() in some controllers, do array_merge with parent::filters()

5) Changing layout

In "UserAdmin/components/AdminDefaultController" change "public $layout" to your layout

6) Links for CMenu

//=========== Main controllers ===========
 
array('label'=>"Users", 'url'=>array('/UserAdmin/user/admin'), 'visible'=>User::checkTask('userAdmin')),
array('label'=>"Roles", 'url'=>array('/UserAdmin/userRole/admin'), 'visible'=>User::checkTask('userRoleAdmin')),
array('label'=>"Tasks", 'url'=>array('/UserAdmin/userTask/admin'), 'visible'=>User::checkRole('isSuperAdmin')),
 
 
//=========== Login, logout, registration, profile ===========
 
array('label'=>"Login", 'url'=>array('/UserAdmin/auth/login'), 'visible'=>!User::checkRole('isGuest')),
array('label'=>"Logout", 'url'=>array('/UserAdmin/auth/logout')),
array('label'=>"Registration", 'url'=>array('/UserAdmin/auth/registration'), 'visible'=>!User::checkRole('isGuest')),
array('label'=>"Profile", 'url'=>array('/UserAdmin/profile/personal'), 'visible'=>(!User::checkRole('isGuest') AND User::checkTask('personalProfileAccess'))),

7) If you want to enable registration

Comment or delete return false in 'UserAdmin/controllers/AuthController' in actionRegistration (line 69)

Usage

To login use: superadmin/superadmin or admin/admin

Now you are ready to go. I suggest you to start from <?php echo CHtml::link('Tasks', array('/UserAdmin/userTask/admin')); ?> and press there a black button "Refresh controllers list".

Additional features

1) In order to make All controller actions available for everyone, add property

public $freeAccess = true; // Optional. It has higher priority than rules from DB

2) In order to make only some of the controller actions available for everyone, add property

public $freeAccessActions = array('index', 'update', 'view'); // Optional. It has higher priority than rules from DB

3) If your controller extends some other controller and you want to set rules for parent controller actions, you can add this property to you parent controller so all this actions will be availiable for moderation in child controllers or add it to the child controller, so it will be availiable for moderation only there

public $moderatedActions = array('index', 'update', 'view'); // Optional.

4) To check user's role, use User::checkRole($roles, $superAdminHasAccess = true)

User::checkRole('isSuperAdmin');
User::checkRole(array('reader', 'moderator', 'player'));  // You can specify array of roles

5) To check user's tasks, use User::checkTask($task, $superAdminHasAccess = true)

User::checkTask('editNews');

6) You can set backend home page for every role (except superadmin, since it's not actually a role). User with this role will be redirected there after login or registration

7) To get current user model

User::getCurrentUser();

8) To get array of user models for specified role

User::getByRole('someRole');

9) To get current user backend home page

User::getCurrentUserHomePage();

10) To get active users use scope active()

User::model()->active()->findAll();

Little candy in the end

There is a nice template controller AdminDefaultController in the 'UserAdmin/components'.

Total 10 comments

#17730 report it
Nathan Phan at 2014/07/17 01:27pm
Using UserAdmin inside another module

Hi

I am trying to use UserAdmin inside another module (Admin)

with Admin module, I am using its module layout.

the problem is: - when I access admin/UserAdmin/user/admin, it does not apply layout and style as Admin module.

How can I fix this?

Thanks

#17151 report it
Vimark at 2014/05/07 04:15pm
RE: Yii Version

Hi, it's not ported to Yii 2 yet, but have plans to do so

#17076 report it
Vulkodava at 2014/04/30 11:05am
Yii Version

Hi, is this extension available for Yii version 2?

#17041 report it
skeef at 2014/04/28 08:47am
Uncorrect isGuest identify

If you login as SuperAdmin module is identify you as SuperAdmin and as Guest! Thats why your menu code don`t correct working in SuperAdmin logon. Solution is to insert false as second argument in User::checkRole :

...
'visible' => User::checkRole('isGuest', false)
...
#16013 report it
Saeed Gholizadeh at 2014/01/09 09:06am
doesn't work

hi

I did 1-2-3 Steps of installation guide but when I want to open /UserAdmin/user/admin or any other link related to module it shows me Page Not Found error

changing 'caseSensitive' to true or false does not effect on result.

#15875 report it
Andrey G. at 2013/12/25 10:19am
i really advice to use built-in RBAC instead of that extension.

It has just no any advantage. All that you need - add GUI for built-in RBAC or get extension that is doing it for you.

Replacing built-in RBAC with something that looks same and more hardcoded is very bad idea, for any real project. As for learning purposes and hobby - fine.

#15854 report it
Vimark at 2013/12/22 03:58pm
Re: Step 4 - Extending base Controller

Well, actually your base "Controller" already extends core yii CController. So it's just about comfort. You can create a lot of such controllers and extend them as you want.

If any other extension will ask you to extend "Controller" from it then you migth have a problems :) Because most probably this "other" extension will want to overwrite method "filters()". So you should somehow merge this two methods.

I doubt that you'll need two extensions from which you should instantiate base "Controller", but if this happens just change "UAccessController" and let it be extended from that "other" extension. And keep rest as usual (Controller extends UAccessController).

Or do create helper middle class. Like this

MyHelperClass extends AnotherExtenstionController
{
}
 
UAccessController extends MyHelperClass
{
}
 
Controller extends UAccessController
{
}

This is drawback of using inheritance instead of composition.

#15852 report it
mem at 2013/12/22 11:07am
Step 4 - Extending base Controller

This seems to be a nice extension. But I don't get one step:

Extend your base "Controller" with "UAccessController"

Do we really need to extend or base controller with something else? What if, another extension arrives and tell us to do the same?

I'm not arguing, I'm totally asking about the possibilities since I'm new on this Yii stuff.

Thanks in advance.

#15835 report it
Vimark at 2013/12/20 04:18pm
Re: profile page

Hi,

User profiles are unique and vary for every projects. I prepare template for fast developing (see UserAdmin/controllers/ProfileController), but you need to implement your own logic.

Same goes for registration: I provide template + code examples and point to them, so developers can easily modify existing or create they own logic.

There are 3 ways to create user profile:

(dirty) Add fields directly to the 'user' table and modify rules() and attribtueLabels() in class User

(clean) Add fields directly to the 'user' table, create some class and extend it from class User. For example:

<?php
class UserWithFields extends User
{
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }
 
    public function rules()
    {
        return CMap::mergeArray(parent::rules(), array(
            array('age, sex', 'required'),
            array('age', 'numerical', 'integerOnly'=>true),
 
            array('age, sex', 'safe', 'on'=>'search'),
        ));
    }
 
    public function attributeLabels()
    {
        return CMap::mergeArray(parent::attributeLabels(), array(
            'age' => 'Age',
            'sex' => 'Gender',
        ));
    }
 
}

(OOP) Create new table with all necessary fields and user_id as foreign key, generate class with gii and use it

P.S.

Well, it looks like people likes this module, so I'm thinking about moving it from gitlab to github and adding new features like:

  • out of the box social networks registration and authorization
  • visit log
  • role based login widgets
  • out of the box profile support
  • optional password mail recovery
  • and so on

If you want something included in this module, you can leave you comments here or on the forum. And I'll add it in future version.

#15833 report it
Maxxer at 2013/12/20 11:58am
Profile page?

Hi. having a look at views/profile/personal.php and it's empty. It says user can change their password but there's no field for that purpose. How come?

Also, is it possible to add custom fields to user profile? I need to add a lot of user data like address, invoicing address and other stuff.

thanks

Leave a comment

Please to leave your comment.

Create extension