cinghie/yii2-user-extended

Module to extend funtionalities of Yii2 User by Dektrium.

Installs: 3 718

Dependents: 2

Suggesters: 0

Security: 0

Stars: 6

Watchers: 6

Forks: 3

Open Issues: 4

Type:yii2-extension

0.6.3 2021-11-29 16:03 UTC

README

License Latest Stable Version Latest Release Date Latest Commit Total Downloads

Yii2 User Extended to extend Yii2 User by Dektrium: https://github.com/dektrium/yii2-user

This is not an standalone module to manage users but a module to extend Yii2 User extension.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require cinghie/yii2-user-extended "*"

or add this line to the require section of your composer.json file.

"cinghie/yii2-user-extended": "*"

Configuration

1. Images folder

Copy img folder to your webroot

2. Update yii2 user database schema

Make sure that you have properly configured db application component and run the following command:

$ php yii migrate/up --migrationPath=@vendor/dektrium/yii2-user/migrations

3. Add Yii2 RBAC migrations

Add to common config file

'components' => [
    'authManager' => [
        'class' => 'yii\rbac\DbManager',
    ],
]

'modules' => [
    'rbac' => 'dektrium\rbac\RbacWebModule',
],

and run migration

$ php yii migrate/up --migrationPath=@yii/rbac/migrations

4. Update yii2 user extended database schema

$ php yii migrate/up --migrationPath=@vendor/cinghie/yii2-user-extended/migrations

5. Set configuration file

Set on your configuration file, in modules section

'modules' =>  [
    // Yii2 RBAC
    'rbac' => [
        'class' => 'dektrium\rbac\Module'
    ],
    // Yii2 User
    'user' => [
        'class' => 'dektrium\user\Module',
        // Yii2 User Controllers Overrides
        'controllerMap' => [
            'admin' => 'cinghie\userextended\controllers\AdminController',
            'security' => 'cinghie\userextended\controllers\SecurityController',
            'settings' => 'cinghie\userextended\controllers\SettingsController'
        ],
        // Yii2 User Models Overrides
        'modelMap' => [
            'RegistrationForm' => 'cinghie\userextended\models\RegistrationForm',
            'Profile' => 'cinghie\userextended\models\Profile',
            'SettingsForm' => 'cinghie\userextended\models\SettingsForm',
            'User' => 'cinghie\userextended\models\User',
        ],
    ],
    // Yii2 User Extended
    'userextended' => [
        'class' => 'cinghie\userextended\Module',
        'avatarPath' => '@webroot/img/users/', // Path to your avatar files
        'avatarURL' => '@web/img/users/', // Url to your avatar files
        'defaultRole' => '', // example 'registered'
        'avatar' => true,
        'bio' => false,
        'captcha' => true,
        'birthday' => true,
        'firstname' => true,
        'gravatarEmail' => false,
        'lastname' => true,
        'location' => false,
        'onlyEmail' => false,
        'publicEmail' => false,
        'signature' => true,
        'templateLogin' => 'login_prestashop', // login or login_prestashop
        'templateLogoURL' => '@web/logo.png', // Url to logo
        'templateRegister' => '_two_column', // _one_column or _two_column
        'terms' => true,
        'website' => false,
        'showTitles' => true, // Set false in adminLTE
    ],
]

and in components section

'components' =>  [
    'view' => [
        'theme' => [
            'pathMap' => [
                '@dektrium/rbac/views/permission' => '@vendor/cinghie/yii2-user-extended/views/permission',  
                '@dektrium/rbac/views/role' => '@vendor/cinghie/yii2-user-extended/views/role',  
                '@dektrium/rbac/views/rule' => '@vendor/cinghie/yii2-user-extended/views/rule',  
                '@dektrium/user/views/admin' => '@vendor/cinghie/yii2-user-extended/views/admin',  
                '@dektrium/user/views/profile' => '@vendor/cinghie/yii2-user-extended/views/profile',  
                '@dektrium/user/views/role' => '@vendor/cinghie/yii2-user-extended/views/role',  
                '@dektrium/user/views/security' => '@vendor/cinghie/yii2-user-extended/views/adminlte/security',  
                '@dektrium/user/views/settings' => '@vendor/cinghie/yii2-user-extended/views/settings',  
            ],
        ],
    ],
]

If you have a Yii2 App Advanced add in Yii2 User Module config

'modules' =>  [

    'user' => [
        'class' => 'dektrium\user\Module',
        // restrict access to recovery and registration controllers from backend
        'as backend' => 'dektrium\user\filters\BackendFilter',
        // Settings
        'enableRegistration' => false,
    ],
    
],		

Or use userextended filter that active profile and settings on backend (dektrium filter disable it)

'modules' =>  [

    'user' => [
        'class' => 'dektrium\user\Module',
        // restrict access to recovery and registration controllers from backend
        'as backend' => 'cinghie\userextended\filters\BackendFilter',
        // Settings
        'enableRegistration' => false,
    ],

],

6. Set captcha in Controller

in your SiteController set in actions() function

'captcha' => [
    'class' => 'yii\captcha\CaptchaAction',
    'minLength' => 6,
    'maxLength' => 6
],

Overrides

Override controller example, on modules config

'modules' => [ 
	
	'userextended' => [ 
		'class' => 'cinghie\userextended\Module',
		'controllerMap' => [
			'items' => 'app\controllers\AdminController',
			'items' => 'app\controllers\SecurityController',
			'items' => 'app\controllers\SettingsController',
		]
	]
	
],

Override models example, on modules config

'modules' => [ 
	
	'userextended' => [ 
		'class' => 'cinghie\userextended\Module',
		'modelMap' => [
			'Account' => 'app\models\Account',
			'Assignment' => 'app\models\Assignment',
			'LoginForm' => 'app\models\LoginForm',
			'Permission' => 'app\models\Permission',
			'Profile' => 'app\models\Profile',
			'RegistrationForm' => 'app\models\RegistrationForm',
			'SettingsForm' => 'app\models\SettingsForm',
			'User' => 'app\models\User',
		]
	]
	
],

Override view example, on components config

'components' => [ 

	'view' => [
		'theme' => [
			'pathMap' => [
				'@cinghie/userextended/views/admin' => '@app/views/userextended/admin',
			],
		],
	],
	
],

Features

  1. Add new fields to user profile (optional params)
    • avatar:
      1. The avatar can be uploaded
      2. The avatar can be updated
      3. On update avatar old image was deleted
    • birthday
    • captcha
    • firstname
    • lastname
    • name (firstname + lastname)
    • signature
    • terms
  2. Add yii2-user fields to user profile like optional params
    • bio
    • gravatar email
    • location
    • public email
    • website
  3. Add default Role on User Registration