Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
2 changes: 1 addition & 1 deletion src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
Expand Down
49 changes: 26 additions & 23 deletions src/migrations/m150214_044831_init_user.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

namespace faro\core\user\migrations;

use Yii;
use yii\db\Schema;
use yii\db\Migration;

Expand All @@ -13,14 +16,14 @@ public function up()
}

// create tables. note the specific order
$this->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',
Expand All @@ -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',
Expand All @@ -46,15 +49,15 @@ 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',
'updated_at' => Schema::TYPE_TIMESTAMP . ' null',
'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',
Expand All @@ -65,32 +68,32 @@ 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')],
]);

// 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'),
Expand All @@ -101,18 +104,18 @@ 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')],
]);
}

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}}');
}
}
9 changes: 9 additions & 0 deletions src/models/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ class Profile extends ActiveRecord
*/
public $module;

/**
* @return string
*/
public static function tableName()
{
return '{{%core_acl_perfil}}';
}


/**
* @inheritdoc
*/
Expand Down
10 changes: 9 additions & 1 deletion src/models/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand All @@ -16,7 +19,7 @@
*
* @property User[] $users
*/
class Role extends ActiveRecord
class Role extends FaroBaseActiveRecord
{
/**
* @var int Admin user role
Expand All @@ -33,6 +36,11 @@ class Role extends ActiveRecord
*/
public $module;

public static function tableName()
{
return '{{%core_acl_rol}}';
}

/**
* @inheritdoc
*/
Expand Down
8 changes: 8 additions & 0 deletions src/models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ class User extends ActiveRecord implements IdentityInterface
*/
public $module;

/**
* @return string
*/
public static function tableName()
{
return '{{%core_acl_usuario}}';
}

/**
* @inheritdoc
*/
Expand Down
9 changes: 9 additions & 0 deletions src/models/UserAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ class UserAuth extends ActiveRecord
*/
public $module;

/**
* @return string
*/
public static function tableName()
{
return '{{%core_acl_usuario_token}}';
}


/**
* @inheritdoc
*/
Expand Down
2 changes: 1 addition & 1 deletion src/models/search/UserSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class UserSearch extends User
*/
public static function tableName()
{
return "{{%user}}";
return "{{%core_acl_usuario}}";
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/views/admin/create.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use faro\core\widgets\Panel;
use yii\helpers\Html;

/**
Expand All @@ -9,18 +10,21 @@
*/

$this->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;
?>
<div class="user-create">

<h1><?= Html::encode($this->title) ?></h1>
<?php Panel::begin(['header' => 'Agregar usuario']) ?>

<?= $this->render('_form', [
'user' => $user,
'profile' => $profile,
]) ?>

<?php Panel::end() ?>

</div>
25 changes: 13 additions & 12 deletions src/views/admin/index.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use faro\core\components\FaroGridView;
use faro\core\widgets\Panel;
use yii\helpers\Html;
use yii\grid\GridView;

Expand All @@ -19,25 +21,23 @@
$this->title = Yii::t('user', 'Users');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="user-index">

<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a(Yii::t('user', 'Create {modelClass}', [
'modelClass' => 'User',
]), ['create'], ['class' => 'btn btn-success']) ?>
</p>

<div class="user-index">

<?php Panel::begin(['header' => 'Listado de usuarios']) ?>

<?php // echo $this->render('_search', ['model' => $searchModel]); ?>

<p>
<?= Html::a(Yii::t('user', 'Create {modelClass}', [
'modelClass' => 'User',
]), ['create'], ['class' => 'btn btn-success']) ?>
</p>

<?php \yii\widgets\Pjax::begin(); ?>
<?= GridView::widget([
<?= FaroGridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],

'id',
[
'attribute' => 'role_id',
Expand Down Expand Up @@ -77,4 +77,5 @@
]); ?>
<?php \yii\widgets\Pjax::end(); ?>

<?php Panel::end() ?>
</div>
Loading