useradmin Complete module for managing users, they premissions, tasks and roles

UserAdmin module

  1. Installation
  2. Usage
  3. Additional features
  4. Little candy in the end

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'.

3 0
19 followers
2 970 downloads
Yii Version: Unknown
License: MIT
Category: Auth
Developed by: Vimark
Created on: Dec 7, 2013
Last updated: 10 years ago

Downloads

show all

Related Extensions