diff --git a/README.md b/README.md index 119470fa..8282deca 100644 --- a/README.md +++ b/README.md @@ -1,233 +1,3 @@ -User management module for Yii 2 -===== - -`This repository is not actively maintained. If you want to add some changes, just fork it and safely use your fork.` - -Perks ---- - -* User management -* RBAC (roles, permissions and stuff) with web interface -* Registration, authorization, password recovery and so on -* Visit log -* Optimised (zero DB queries during usual user workflow) -* Nice widgets like GhostMenu or GhostHtml::a where elements are visible only if user has access to route where they point - - -Installation ------------- - -The preferred way to install this extension is through [composer](http://getcomposer.org/download/). - -Either run - -``` -composer require webvimark/module-user-management -``` - -or add - -``` -"webvimark/module-user-management": "^1" -``` - -to the require section of your `composer.json` file. - -Configuration ---- - -1) In your config/web.php - -```php - -'components'=>[ - 'user' => [ - 'class' => 'webvimark\modules\UserManagement\components\UserConfig', - - // Comment this if you don't want to record user logins - 'on afterLogin' => function($event) { - \webvimark\modules\UserManagement\models\UserVisitLog::newVisitor($event->identity->id); - } - ], -], - -'modules'=>[ - 'user-management' => [ - 'class' => 'webvimark\modules\UserManagement\UserManagementModule', - - // 'enableRegistration' => true, - - // Add regexp validation to passwords. Default pattern does not restrict user and can enter any set of characters. - // The example below allows user to enter : - // any set of characters - // (?=\S{8,}): of at least length 8 - // (?=\S*[a-z]): containing at least one lowercase letter - // (?=\S*[A-Z]): and at least one uppercase letter - // (?=\S*[\d]): and at least one number - // $: anchored to the end of the string - - //'passwordRegexp' => '^\S*(?=\S{8,})(?=\S*[a-z])(?=\S*[A-Z])(?=\S*[\d])\S*$', - - - // Here you can set your handler to change layout for any controller or action - // Tip: you can use this event in any module - 'on beforeAction'=>function(yii\base\ActionEvent $event) { - if ( $event->action->uniqueId == 'user-management/auth/login' ) - { - $event->action->controller->layout = 'loginLayout.php'; - }; - }, - ], -], - -``` - -To learn about events check: - -* http://www.yiiframework.com/doc-2.0/guide-concept-events.html -* http://www.yiiframework.com/doc-2.0/guide-concept-configurations.html#configuration-format - -Layout handler example in *AuthHelper::layoutHandler()* - -To see full list of options check *UserManagementModule* file - - -2) In your config/console.php (this is needed for migrations and working with console) - -```php - -'modules'=>[ - 'user-management' => [ - 'class' => 'webvimark\modules\UserManagement\UserManagementModule', - 'controllerNamespace'=>'vendor\webvimark\modules\UserManagement\controllers', // To prevent yii help from crashing - ], -], - -``` - -3) Run migrations - -```php - -./yii migrate --migrationPath=vendor/webvimark/module-user-management/migrations/ - -``` - -4) In you base controller - -```php - -public function behaviors() -{ - return [ - 'ghost-access'=> [ - 'class' => 'webvimark\modules\UserManagement\components\GhostAccessControl', - ], - ]; -} - -``` - -Where you can go ------ - -```php - -false, - 'activateParents'=>true, - 'items' => [ - [ - 'label' => 'Backend routes', - 'items'=>UserManagementModule::menuItems() - ], - [ - 'label' => 'Frontend routes', - 'items'=>[ - ['label'=>'Login', 'url'=>['/user-management/auth/login']], - ['label'=>'Logout', 'url'=>['/user-management/auth/logout']], - ['label'=>'Registration', 'url'=>['/user-management/auth/registration']], - ['label'=>'Change own password', 'url'=>['/user-management/auth/change-own-password']], - ['label'=>'Password recovery', 'url'=>['/user-management/auth/password-recovery']], - ['label'=>'E-mail confirmation', 'url'=>['/user-management/auth/confirm-email']], - ], - ], - ], -]); -?> - -``` - -First steps ---- - -From the menu above at first you'll se only 2 element: "Login" and "Logout" because you have no permission to visit other urls -and to render menu we using **GhostMenu::widget()**. It's render only element that active user can visit. - -Also same functionality has **GhostNav::widget()** and **GhostHtml:a()** - -1) Login as superadmin/superadmin - -2) Go to "Permissions" and play there - -3) Go to "Roles" and play there - -4) Go to "User" and play there - -5) Relax - - -Usage ---- - -You controllers may have two properties that will make whole controller or selected action accessible to everyone - -```php -public $freeAccess = true; - -``` - -Or - -```php -public $freeAccessActions = ['first-action', 'another-action']; - -``` - -Here are list of the useful helpers. For detailed explanation look in the corresponding functions. - -```php - -User::hasRole($roles, $superAdminAllowed = true) -User::hasPermission($permission, $superAdminAllowed = true) -User::canRoute($route, $superAdminAllowed = true) - -User::assignRole($userId, $roleName) -User::revokeRole($userId, $roleName) - -User::getCurrentUser($fromSingleton = true) - -``` - -Role, Permission and Route all have following methods - -```php - -Role::create($name, $description = null, $groupCode = null, $ruleName = null, $data = null) -Role::addChildren($parentName, $childrenNames, $throwException = false) -Role::removeChildren($parentName, $childrenNames) - -``` - - -Events ------- - -Events can be handled via config file like following ```php @@ -239,32 +9,3 @@ Events can be handled via config file like following }, ], ], - -``` - -List of supported events can be found in *UserAuthEvent* class - -FAQ ---- - -**Question**: Do you have API docs? - -**Answer**: Check this one http://opensource.id5.com.br/webvimark/doc/index.html (Credits to [lukBarros](https://github.com/lukBarros)) - -**Question**: I want users to register and login with they e-mails! Mmmmm... And they should confirm it too! - -**Answer**: See configuration properties *$useEmailAsLogin* and *$emailConfirmationRequired* - -**Question**: I want to have profile for user with avatar, birthday and stuff. What should I do ? - -**Answer**: Profiles are to project-specific, so you'll have to implement them yourself (but you can find example here - https://github.com/webvimark/user-management/wiki/Profile-and-custom-registration). Here is how to do it without modifying this module - -1) Create table and model for profile, that have user_id (connect with "user" table) - -2) Check AuthController::actionRegistration() how it works (*you can skip this part*) - -3) Define your layout for registration. Check example in *AuthHelper::layoutHandler()*. Now use theming to change registraion.php file - -4) Define your own UserManagementModule::$registrationFormClass. In this class you can do whatever you want like validating custom forms and saving profiles - -5) Create your controller where user can view profiles diff --git a/UserManagementModule.php b/UserManagementModule.php index 75717919..47842242 100644 --- a/UserManagementModule.php +++ b/UserManagementModule.php @@ -1,6 +1,6 @@ ['webvimark\modules\UserManagement\components\AuthHelper', 'layoutHandler'], + * 'on beforeAction'=>['xvetx\modules\UserManagement\components\AuthHelper', 'layoutHandler'], * * @param \yii\base\ActionEvent $event */ @@ -147,6 +147,8 @@ public static function unifyRoute($route) // If it's not clean url like localhost/folder/index.php/bla-bla then remove // baseUrl and leave only relative path 'bla-bla' + //Ввиду того что у нас шаблон advanced нам это приводит к конфликту site.com/admin/admin-payment - будет без доступа + /** if ( $baseUrl ) { if ( strpos($routeAsString, $baseUrl) === 0 ) @@ -154,6 +156,7 @@ public static function unifyRoute($route) $routeAsString = substr_replace($routeAsString, '', 0, strlen($baseUrl)); } } + **/ $languagePrefix = '/' . Yii::$app->language . '/'; @@ -350,6 +353,18 @@ private static function getControllerRoutes($module, $namespace, $prefix, &$resu $className = $namespace . Inflector::id2camel($id) . 'Controller'; if ( strpos($className, '-') === false && class_exists($className) && is_subclass_of($className, 'yii\base\Controller') ) { + if($className =='Da\User\Controller\AbstractAuthItemController') continue; + if($className =='Da\User\Controller\api\v1\AdminController') continue; + if($id =='admin') continue; + if($prefix . $id =='admin') continue; + if($prefix . $id =='permission') continue; + if($prefix . $id =='profile') continue; + if($prefix . $id =='recovery') continue; + if($prefix . $id =='registration') continue; + if($prefix . $id =='role') continue; + if($prefix . $id =='security') continue; + if($prefix . $id =='settings') continue; + $controller = new $className($prefix . $id, $module); self::getActionRoutes($controller, $result); $result[] = '/' . $controller->uniqueId . '/*'; @@ -358,4 +373,4 @@ private static function getControllerRoutes($module, $namespace, $prefix, &$resu } } } -} \ No newline at end of file +} diff --git a/components/GhostAccessControl.php b/components/GhostAccessControl.php index fd7d7e5b..d48ca3e9 100644 --- a/components/GhostAccessControl.php +++ b/components/GhostAccessControl.php @@ -1,9 +1,9 @@ User::canRoute($item['url') will be added * - * @package webvimark\modules\UserManagement\components + * @package xvetx\modules\UserManagement\components */ class GhostMenu extends Menu { diff --git a/components/GhostNav.php b/components/GhostNav.php index 2417705e..ceaa85c1 100644 --- a/components/GhostNav.php +++ b/components/GhostNav.php @@ -1,7 +1,7 @@ User::canRoute($item['url') will be added * - * @package webvimark\modules\UserManagement\components + * @package xvetx\modules\UserManagement\components */ class GhostNav extends Nav { diff --git a/components/UserAuthEvent.php b/components/UserAuthEvent.php index c713a20e..887ed4f6 100644 --- a/components/UserAuthEvent.php +++ b/components/UserAuthEvent.php @@ -1,10 +1,10 @@ 'webvimark\modules\UserManagement\models\User', + 'targetClass' => 'xvetx\modules\UserManagement\models\User', 'targetAttribute' => 'username', ], diff --git a/models/rbacDB/AbstractItem.php b/models/rbacDB/AbstractItem.php index fae8ae59..d28d7aeb 100644 --- a/models/rbacDB/AbstractItem.php +++ b/models/rbacDB/AbstractItem.php @@ -1,9 +1,9 @@ trigger(get_called_class(), self::EVENT_BEFORE_ADD_CHILDREN, $event); } - public static function beforeRemoveChildren($parentName, $childrenNames) + /** + * @param $parentName + * @param $childrenNames + * @param bool $throwException + */ + public static function beforeRemoveChildren($parentName, $childrenNames, $throwException = false) { $event = new AbstractItemEvent(compact('parentName', 'childrenNames', 'throwException')); $event->trigger(get_called_class(), self::EVENT_BEFORE_REMOVE_CHILDREN, $event); diff --git a/models/rbacDB/AuthItemGroup.php b/models/rbacDB/AuthItemGroup.php index ce5710fe..ead1ed5a 100644 --- a/models/rbacDB/AuthItemGroup.php +++ b/models/rbacDB/AuthItemGroup.php @@ -1,8 +1,8 @@ diff --git a/views/auth-item-group/create.php b/views/auth-item-group/create.php index f1214c58..394c6cd6 100644 --- a/views/auth-item-group/create.php +++ b/views/auth-item-group/create.php @@ -1,11 +1,11 @@ title = UserManagementModule::t('back', 'Creating permission group'); diff --git a/views/auth-item-group/index.php b/views/auth-item-group/index.php index 51a37134..edde11bc 100644 --- a/views/auth-item-group/index.php +++ b/views/auth-item-group/index.php @@ -1,7 +1,7 @@ title = UserManagementModule::t('back', 'Permission groups'); diff --git a/views/auth-item-group/update.php b/views/auth-item-group/update.php index 1d3520c7..f2ff5c31 100644 --- a/views/auth-item-group/update.php +++ b/views/auth-item-group/update.php @@ -1,11 +1,11 @@ title = UserManagementModule::t('back', 'Editing permission group') . ': ' . $model->name; diff --git a/views/auth-item-group/view.php b/views/auth-item-group/view.php index b3b289a3..e95fb68f 100644 --- a/views/auth-item-group/view.php +++ b/views/auth-item-group/view.php @@ -1,12 +1,12 @@ title = $model->name; diff --git a/views/auth/changeOwnPassword.php b/views/auth/changeOwnPassword.php index 9985fec8..fffda333 100644 --- a/views/auth/changeOwnPassword.php +++ b/views/auth/changeOwnPassword.php @@ -1,12 +1,12 @@ title = UserManagementModule::t('back', 'Change own password'); diff --git a/views/auth/changeOwnPasswordSuccess.php b/views/auth/changeOwnPasswordSuccess.php index 88e0a4f9..a8b209c8 100644 --- a/views/auth/changeOwnPasswordSuccess.php +++ b/views/auth/changeOwnPasswordSuccess.php @@ -1,6 +1,6 @@ title = UserManagementModule::t('front', 'Confirm E-mail'); diff --git a/views/auth/confirmEmailSuccess.php b/views/auth/confirmEmailSuccess.php index 7bd4c0e7..403d3944 100644 --- a/views/auth/confirmEmailSuccess.php +++ b/views/auth/confirmEmailSuccess.php @@ -1,11 +1,11 @@ title = UserManagementModule::t('front', 'E-mail confirmed'); diff --git a/views/auth/login.php b/views/auth/login.php index 25d7b088..d5a2d0c7 100644 --- a/views/auth/login.php +++ b/views/auth/login.php @@ -1,11 +1,11 @@ diff --git a/views/auth/passwordRecovery.php b/views/auth/passwordRecovery.php index b834c6d0..d07a5385 100644 --- a/views/auth/passwordRecovery.php +++ b/views/auth/passwordRecovery.php @@ -1,13 +1,13 @@ title = UserManagementModule::t('front', 'Password recovery'); diff --git a/views/auth/passwordRecoverySuccess.php b/views/auth/passwordRecoverySuccess.php index bc7b678f..aa8dac11 100644 --- a/views/auth/passwordRecoverySuccess.php +++ b/views/auth/passwordRecoverySuccess.php @@ -1,6 +1,6 @@ title = UserManagementModule::t('front', 'Registration'); diff --git a/views/auth/registrationWaitForEmailConfirmation.php b/views/auth/registrationWaitForEmailConfirmation.php index 05805288..53d0afc1 100644 --- a/views/auth/registrationWaitForEmailConfirmation.php +++ b/views/auth/registrationWaitForEmailConfirmation.php @@ -1,10 +1,10 @@ title = UserManagementModule::t('front', 'Registration - confirm your e-mail'); diff --git a/views/layouts/loginLayout.php b/views/layouts/loginLayout.php index a728287d..c906f962 100644 --- a/views/layouts/loginLayout.php +++ b/views/layouts/loginLayout.php @@ -1,6 +1,6 @@ title = UserManagementModule::t('back', 'Permission creation'); $this->params['breadcrumbs'][] = ['label' => UserManagementModule::t('back', 'Permissions'), 'url' => ['index']]; diff --git a/views/permission/index.php b/views/permission/index.php index 4f8796a2..6d778d35 100644 --- a/views/permission/index.php +++ b/views/permission/index.php @@ -1,10 +1,10 @@ title = UserManagementModule::t('back', 'Permissions'); diff --git a/views/permission/update.php b/views/permission/update.php index b2736079..f84ce8af 100644 --- a/views/permission/update.php +++ b/views/permission/update.php @@ -1,10 +1,10 @@ title = UserManagementModule::t('back', 'Editing permission: ') . ' ' . $model->name; $this->params['breadcrumbs'][] = ['label' => UserManagementModule::t('back', 'Permissions'), 'url' => ['index']]; diff --git a/views/permission/view.php b/views/permission/view.php index a28af200..7bc5cf77 100644 --- a/views/permission/view.php +++ b/views/permission/view.php @@ -9,8 +9,8 @@ * @var yii\rbac\Permission $item */ -use webvimark\modules\UserManagement\components\GhostHtml; -use webvimark\modules\UserManagement\UserManagementModule; +use xvetx\modules\UserManagement\components\GhostHtml; +use xvetx\modules\UserManagement\UserManagementModule; use yii\helpers\ArrayHelper; use yii\helpers\Html; diff --git a/views/role/_form.php b/views/role/_form.php index 764e92ff..b0637082 100644 --- a/views/role/_form.php +++ b/views/role/_form.php @@ -1,10 +1,10 @@ title = UserManagementModule::t('back', 'Role creation'); $this->params['breadcrumbs'][] = ['label' => UserManagementModule::t('back', 'Roles'), 'url' => ['index']]; diff --git a/views/role/index.php b/views/role/index.php index 6d09e1b3..53f35e01 100644 --- a/views/role/index.php +++ b/views/role/index.php @@ -1,10 +1,10 @@ title = UserManagementModule::t('back', 'Roles'); diff --git a/views/role/update.php b/views/role/update.php index 8c28b7b1..aa66ab19 100644 --- a/views/role/update.php +++ b/views/role/update.php @@ -1,10 +1,10 @@ title = UserManagementModule::t('back', 'Editing role: ') . ' ' . $model->name; $this->params['breadcrumbs'][] = ['label' => UserManagementModule::t('back', 'Roles'), 'url' => ['index']]; diff --git a/views/role/view.php b/views/role/view.php index 2754628e..8528f255 100644 --- a/views/role/view.php +++ b/views/role/view.php @@ -10,9 +10,9 @@ * @var yii\rbac\Role $role */ -use webvimark\modules\UserManagement\components\GhostHtml; -use webvimark\modules\UserManagement\models\rbacDB\Role; -use webvimark\modules\UserManagement\UserManagementModule; +use xvetx\modules\UserManagement\components\GhostHtml; +use xvetx\modules\UserManagement\models\rbacDB\Role; +use xvetx\modules\UserManagement\UserManagementModule; use yii\helpers\ArrayHelper; use yii\helpers\Html; diff --git a/views/user-permission/set.php b/views/user-permission/set.php index 462a72d2..6e44615a 100644 --- a/views/user-permission/set.php +++ b/views/user-permission/set.php @@ -2,12 +2,12 @@ /** * @var yii\web\View $this * @var array $permissionsByGroup - * @var webvimark\modules\UserManagement\models\User $user + * @var xvetx\modules\UserManagement\models\User $user */ -use webvimark\modules\UserManagement\components\GhostHtml; -use webvimark\modules\UserManagement\models\rbacDB\Role; -use webvimark\modules\UserManagement\UserManagementModule; +use xvetx\modules\UserManagement\components\GhostHtml; +use xvetx\modules\UserManagement\models\rbacDB\Role; +use xvetx\modules\UserManagement\UserManagementModule; use yii\bootstrap\BootstrapPluginAsset; use yii\helpers\ArrayHelper; use yii\helpers\Html; diff --git a/views/user-visit-log/index.php b/views/user-visit-log/index.php index 4d70a702..abb1f3e0 100644 --- a/views/user-visit-log/index.php +++ b/views/user-visit-log/index.php @@ -1,7 +1,7 @@ title = UserManagementModule::t('back', 'Visit log'); diff --git a/views/user-visit-log/view.php b/views/user-visit-log/view.php index ce7a0731..e6290f17 100644 --- a/views/user-visit-log/view.php +++ b/views/user-visit-log/view.php @@ -1,12 +1,12 @@ title = $model->id; diff --git a/views/user/_form.php b/views/user/_form.php index e828d60f..45c99ccd 100644 --- a/views/user/_form.php +++ b/views/user/_form.php @@ -1,14 +1,14 @@ diff --git a/views/user/_search.php b/views/user/_search.php index d5f0c455..a67415e2 100644 --- a/views/user/_search.php +++ b/views/user/_search.php @@ -5,7 +5,7 @@ /** * @var yii\web\View $this - * @var webvimark\modules\UserManagement\models\search\UserSearch $model + * @var xvetx\modules\UserManagement\models\search\UserSearch $model * @var yii\widgets\ActiveForm $form */ ?> diff --git a/views/user/changePassword.php b/views/user/changePassword.php index 1ec181c0..94242daf 100644 --- a/views/user/changePassword.php +++ b/views/user/changePassword.php @@ -1,12 +1,12 @@ title = UserManagementModule::t('back', 'Changing password for user: ') . ' ' . $model->username; diff --git a/views/user/create.php b/views/user/create.php index f890c518..f04dffa1 100644 --- a/views/user/create.php +++ b/views/user/create.php @@ -1,11 +1,11 @@ title = UserManagementModule::t('back', 'User creation'); diff --git a/views/user/index.php b/views/user/index.php index 2c5a6565..68281e0f 100644 --- a/views/user/index.php +++ b/views/user/index.php @@ -1,9 +1,9 @@ title = UserManagementModule::t('back', 'Users'); diff --git a/views/user/update.php b/views/user/update.php index 0a4ef0a1..e9248de6 100644 --- a/views/user/update.php +++ b/views/user/update.php @@ -1,14 +1,14 @@ title = UserManagementModule::t('back', 'Editing user: ') . ' ' . $model->username; diff --git a/views/user/view.php b/views/user/view.php index 5623a29b..af9244e1 100644 --- a/views/user/view.php +++ b/views/user/view.php @@ -1,16 +1,16 @@ title = $model->username;