diff --git a/composer.json b/composer.json index 6bbd684..bd036d3 100644 --- a/composer.json +++ b/composer.json @@ -13,9 +13,32 @@ ], "require": { "yiisoft/yii2": "*", - "yiisoft/yii2-authclient": "*" + "yiisoft/yii2-authclient": "*", + "faro/core": "dev-feature-acl" }, "autoload": { "psr-4": { "faro\\core\\user\\": "src" } - } + }, + "repositories": [ + { + "type": "composer", + "url": "https://asset-packagist.org" + }, + { + "type": "vcs", + "url": "git@github.com:FARO-DataLab/faro-core.git" + }, + { + "type": "vcs", + "url": "git@github.com:FARO-DataLab/faro-media.git" + }, + { + "type": "vcs", + "url": "git@github.com:FARO-DataLab/faro-googleanalytics.git" + }, + { + "type": "vcs", + "url": "git@github.com:FARO-DataLab/yii2-user.git" + } + ] } \ No newline at end of file diff --git a/src/Module.php b/src/Module.php index d0d58aa..81429d2 100644 --- a/src/Module.php +++ b/src/Module.php @@ -21,7 +21,7 @@ class Module extends \yii\base\Module /** * @var string Alias for module */ - public $alias = "@user"; + public $alias = "@faro/core/user"; /** * @var bool If true, users are required to enter an email diff --git a/src/controllers/DefaultController.php b/src/controllers/DefaultController.php index df8dfca..561249f 100644 --- a/src/controllers/DefaultController.php +++ b/src/controllers/DefaultController.php @@ -84,6 +84,8 @@ public function actionLogin() $returnUrl = $this->performLogin($model->getUser(), $model->rememberMe); return $this->redirect($returnUrl); } + + $this->layout = "@vendor/faro/core/src/themes/dmp2020/layouts/login"; return $this->render('login', compact("model")); } diff --git a/src/migrations/m150214_044831_init_user.php b/src/migrations/m150214_044831_init_user.php index 058f620..7041fbc 100644 --- a/src/migrations/m150214_044831_init_user.php +++ b/src/migrations/m150214_044831_init_user.php @@ -1,5 +1,8 @@ createTable('{{%role}}', [ + $this->createTable('{{%core_acl_rol}}', [ 'id' => Schema::TYPE_PK, 'name' => Schema::TYPE_STRING . ' not null', 'created_at' => Schema::TYPE_TIMESTAMP . ' null', 'updated_at' => Schema::TYPE_TIMESTAMP . ' null', 'can_admin' => Schema::TYPE_SMALLINT . ' not null default 0', ], $tableOptions); - $this->createTable('{{%user}}', [ + $this->createTable('{{%core_acl_usuario}}', [ 'id' => Schema::TYPE_PK, 'role_id' => Schema::TYPE_INTEGER . ' not null', 'status' => Schema::TYPE_SMALLINT . ' not null', @@ -37,7 +40,7 @@ public function up() 'banned_at' => Schema::TYPE_TIMESTAMP . ' null', 'banned_reason' => Schema::TYPE_STRING . ' null', ], $tableOptions); - $this->createTable('{{%user_token}}', [ + $this->createTable('{{%core_acl_usuario_token}}', [ 'id' => Schema::TYPE_PK, 'user_id' => Schema::TYPE_INTEGER . ' null', 'type' => Schema::TYPE_SMALLINT . ' not null', @@ -46,7 +49,7 @@ public function up() 'created_at' => Schema::TYPE_TIMESTAMP . ' null', 'expired_at' => Schema::TYPE_TIMESTAMP . ' null', ], $tableOptions); - $this->createTable('{{%profile}}', [ + $this->createTable('{{%core_acl_perfil}}', [ 'id' => Schema::TYPE_PK, 'user_id' => Schema::TYPE_INTEGER . ' not null', 'created_at' => Schema::TYPE_TIMESTAMP . ' null', @@ -54,7 +57,7 @@ public function up() 'full_name' => Schema::TYPE_STRING . ' null', 'timezone' => Schema::TYPE_STRING . ' null', ], $tableOptions); - $this->createTable('{{%user_auth}}', [ + $this->createTable('{{%core_acl_usuario_auth}}', [ 'id' => Schema::TYPE_PK, 'user_id' => Schema::TYPE_INTEGER . ' not null', 'provider' => Schema::TYPE_STRING . ' not null', @@ -65,20 +68,20 @@ public function up() ], $tableOptions); // add indexes for performance optimization - $this->createIndex('{{%user_email}}', '{{%user}}', 'email', true); - $this->createIndex('{{%user_username}}', '{{%user}}', 'username', true); - $this->createIndex('{{%user_token_token}}', '{{%user_token}}', 'token', true); - $this->createIndex('{{%user_auth_provider_id}}', '{{%user_auth}}', 'provider_id', false); + $this->createIndex('{{%core_acl_usuario_email}}', '{{%core_acl_usuario}}', 'email', true); + $this->createIndex('{{%core_acl_usuario_username}}', '{{%core_acl_usuario}}', 'username', true); + $this->createIndex('{{%core_acl_usuario_token_token}}', '{{%core_acl_usuario_token}}', 'token', true); + $this->createIndex('{{%core_acl_usuario_auth_provider_id}}', '{{%core_acl_usuario_auth}}', 'provider_id', false); // add foreign keys for data integrity - $this->addForeignKey('{{%user_role_id}}', '{{%user}}', 'role_id', '{{%role}}', 'id'); - $this->addForeignKey('{{%profile_user_id}}', '{{%profile}}', 'user_id', '{{%user}}', 'id'); - $this->addForeignKey('{{%user_token_user_id}}', '{{%user_token}}', 'user_id', '{{%user}}', 'id'); - $this->addForeignKey('{{%user_auth_user_id}}', '{{%user_auth}}', 'user_id', '{{%user}}', 'id'); + $this->addForeignKey('{{%core_acl_usuario_role_id}}', '{{%core_acl_usuario}}', 'role_id', '{{%core_acl_rol}}', 'id'); + $this->addForeignKey('{{%core_acl_perfil_user_id}}', '{{%core_acl_perfil}}', 'user_id', '{{%core_acl_usuario}}', 'id'); + $this->addForeignKey('{{%core_acl_usuario_token_user_id}}', '{{%core_acl_usuario_token}}', 'user_id', '{{%core_acl_usuario}}', 'id'); + $this->addForeignKey('{{%core_acl_usuario_auth_user_id}}', '{{%core_acl_usuario_auth}}', 'user_id', '{{%core_acl_usuario}}', 'id'); // insert role data $columns = ['name', 'can_admin', 'created_at']; - $this->batchInsert('{{%role}}', $columns, [ + $this->batchInsert('{{%core_acl_rol}}', $columns, [ ['Admin', 1, gmdate('Y-m-d H:i:s')], ['User', 0, gmdate('Y-m-d H:i:s')], ]); @@ -86,11 +89,11 @@ public function up() // insert admin user: neo/neo $security = Yii::$app->security; $columns = ['role_id', 'email', 'username', 'password', 'status', 'created_at', 'access_token', 'auth_key']; - $this->batchInsert('{{%user}}', $columns, [ + $this->batchInsert('{{%core_acl_usuario}}', $columns, [ [ 1, // Role::ROLE_ADMIN - 'neo@neo.com', - 'neo', + 'admin@faro.works', + 'admin', '$2y$13$dyVw4WkZGkABf2UrGWrhHO4ZmVBv.K4puhOL59Y9jQhIdj63TlV.O', // neo 1, // User::STATUS_ACTIVE gmdate('Y-m-d H:i:s'), @@ -101,7 +104,7 @@ public function up() // insert profile data $columns = ['user_id', 'full_name', 'created_at']; - $this->batchInsert('{{%profile}}', $columns, [ + $this->batchInsert('{{%core_acl_perfil}}', $columns, [ [1, 'the one', gmdate('Y-m-d H:i:s')], ]); } @@ -109,10 +112,10 @@ public function up() public function down() { // drop tables in reverse order (for foreign key constraints) - $this->dropTable('{{%user_auth}}'); - $this->dropTable('{{%profile}}'); - $this->dropTable('{{%user_token}}'); - $this->dropTable('{{%user}}'); - $this->dropTable('{{%role}}'); + $this->dropTable('{{%core_acl_usuario_auth}}'); + $this->dropTable('{{%core_acl_perfil}}'); + $this->dropTable('{{%core_acl_usuario_token}}'); + $this->dropTable('{{%core_acl_usuario}}'); + $this->dropTable('{{%core_acl_rol}}'); } } diff --git a/src/models/Profile.php b/src/models/Profile.php index 074b64b..3b2c0b5 100644 --- a/src/models/Profile.php +++ b/src/models/Profile.php @@ -24,6 +24,15 @@ class Profile extends ActiveRecord */ public $module; + /** + * @return string + */ + public static function tableName() + { + return '{{%core_acl_perfil}}'; + } + + /** * @inheritdoc */ diff --git a/src/models/Role.php b/src/models/Role.php index ea60723..402c6d2 100644 --- a/src/models/Role.php +++ b/src/models/Role.php @@ -2,8 +2,11 @@ namespace faro\core\user\models; +use faro\core\models\FaroBaseActiveRecord; use Yii; use yii\db\ActiveRecord; +use yii\helpers\Inflector; +use yii\helpers\StringHelper; /** * This is the model class for table "tbl_role". @@ -16,7 +19,7 @@ * * @property User[] $users */ -class Role extends ActiveRecord +class Role extends FaroBaseActiveRecord { /** * @var int Admin user role @@ -33,6 +36,11 @@ class Role extends ActiveRecord */ public $module; + public static function tableName() + { + return '{{%core_acl_rol}}'; + } + /** * @inheritdoc */ diff --git a/src/models/User.php b/src/models/User.php index c98c70d..d9fd44e 100644 --- a/src/models/User.php +++ b/src/models/User.php @@ -76,6 +76,14 @@ class User extends ActiveRecord implements IdentityInterface */ public $module; + /** + * @return string + */ + public static function tableName() + { + return '{{%core_acl_usuario}}'; + } + /** * @inheritdoc */ diff --git a/src/models/UserAuth.php b/src/models/UserAuth.php index a39e8b2..20bc4c4 100644 --- a/src/models/UserAuth.php +++ b/src/models/UserAuth.php @@ -25,6 +25,15 @@ class UserAuth extends ActiveRecord */ public $module; + /** + * @return string + */ + public static function tableName() + { + return '{{%core_acl_usuario_token}}'; + } + + /** * @inheritdoc */ diff --git a/src/models/search/UserSearch.php b/src/models/search/UserSearch.php index 3b6cc0e..468ee36 100644 --- a/src/models/search/UserSearch.php +++ b/src/models/search/UserSearch.php @@ -17,7 +17,7 @@ class UserSearch extends User */ public static function tableName() { - return "{{%user}}"; + return "{{%core_acl_usuario}}"; } /** diff --git a/src/views/admin/create.php b/src/views/admin/create.php index 57b384f..babcd2e 100644 --- a/src/views/admin/create.php +++ b/src/views/admin/create.php @@ -1,5 +1,6 @@ title = Yii::t('user', 'Create {modelClass}', [ - 'modelClass' => 'User', + 'modelClass' => 'Usuario', ]); + $this->params['breadcrumbs'][] = ['label' => Yii::t('user', 'Users'), 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; ?>
+ = Html::a(Yii::t('user', 'Create {modelClass}', [ + 'modelClass' => 'User', + ]), ['create'], ['class' => 'btn btn-success']) ?> +
+- = Html::a(Yii::t('user', 'Create {modelClass}', [ - 'modelClass' => 'User', - ]), ['create'], ['class' => 'btn btn-success']) ?> -
- - = GridView::widget([ + = FaroGridView::widget([ 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [ - ['class' => 'yii\grid\SerialColumn'], - 'id', [ 'attribute' => 'role_id', @@ -77,4 +77,5 @@ ]); ?> ++ = Html::a(Yii::t('user', 'Update'), ['update', 'id' => $user->id], ['class' => 'btn btn-primary']) ?> + = Html::a(Yii::t('user', 'Delete'), ['delete', 'id' => $user->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => Yii::t('user', 'Are you sure you want to delete this item?'), + 'method' => 'post', + ], + ]) ?> +
-- = Html::a(Yii::t('user', 'Update'), ['update', 'id' => $user->id], ['class' => 'btn btn-primary']) ?> - = Html::a(Yii::t('user', 'Delete'), ['delete', 'id' => $user->id], [ - 'class' => 'btn btn-danger', - 'data' => [ - 'confirm' => Yii::t('user', 'Are you sure you want to delete this item?'), - 'method' => 'post', - ], - ]) ?> -
+= $flash ?>
-