Skip to content

Commit

Permalink
Merge pull request #538 from TonisOrmisson/v2-docs-migration-1
Browse files Browse the repository at this point in the history
V2. Keep old bootstrap 3 view files included in separate folder, add mailViewsPath
  • Loading branch information
maxxer authored Feb 27, 2024
2 parents 7e5583a + f60976c commit 3936757
Show file tree
Hide file tree
Showing 98 changed files with 3,069 additions and 18 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ jobs:
fail-fast: false
matrix:
operating-system: ['ubuntu-latest']
php-versions: ['8.2','8.1', '8.0','7.4']
php-versions: ['8.3', '8.2','8.1', '8.0','7.4']

services:
mariadb:
image: mariadb:10
image: mariadb:latest
ports:
- 3306:3306
env:
MYSQL_USER: user
MYSQL_PASSWORD: password
MYSQL_DATABASE: yii2-usuario-test
MYSQL_ROOT_PASSWORD: password
options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3
options: --health-cmd="healthcheck.sh --connect --innodb_initialized" --health-interval=5s --health-timeout=5s --health-retries=3

steps:

Expand Down
31 changes: 31 additions & 0 deletions docs/guides/migrating-to-v2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Migrating from v1 to v2


The main change in v2 is decoupling the UI framework from the module base code in order to allow supporting mulitple
UI frameworks simultaneously. Eg bootstrab 3/4/5 or any other ui framework. To be able to do this v2 is not including
the Bootstrap as a required dependency anymore.

The module includes the view files for both Bootstrap 3 and Bootstrap 5. The default views for v2 are Bootstrap 5, but
either way the bootstrap dependencies must be specified by your project composer.json requirements depending on which
version you choose to use.

## Using with old Bootstrap 3
In order to continue with the _old_ Bootstrap 3 views. you need to:

1. make sure you have the followin packakges included in your composer.json "require" section:
```
"2amigos/yii2-selectize-widget": "^1.1",
"yiisoft/yii2-bootstrap": "^2.0",
```

2. Change the usuario Module 'viewPath' paramater to a folder containing Bootstrap 3 views, eg the included:
`'viewPath' => '@Da/User/resources/views/bootstrap3',`

## Using with old Bootstrap 5
1. make sure you have the followin packakges included in your composer.json "require" section:
```
"yiisoft/yii2-bootstrap5",
"kartik-v/yii2-widget-select",
"twbs/bootstrap-icons",
```
2. The default 'viewPath' for v2 Module is Bootstrap 5 views in '@Da/User/resources/views/bootstrap5'.
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ Helpful Guides
- [Separate Frontend and Backend Sessions](guides/separate-frontend-and-backend-sessions.md)
- [Social Network Authentication](guides/social-network-authentication.md)
- [How to Enable session history](guides/how-to-use-session-history.md)
- [Migrating from v1 to v2](guides/migrating-to-v2.md)

Contributing
------------
Expand Down
3 changes: 2 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ parameters:
paths:
- src
excludePaths:
- 'src/resources/i18n/*'
- 'src/User/resources/i18n/*'
- 'src/User/resources/views/bootstrap3/*'
bootstrapFiles:
- stan_autoload.php
6 changes: 5 additions & 1 deletion src/User/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,11 @@ class Module extends BaseModule
/**
* @var string
*/
public $viewPath = '@Da/User/resources/views';
public $viewPath = '@Da/User/resources/views/bootstrap5';
/**
* @var string the mail views path is UI framework independent
*/
public $mailViewPath = '@Da/User/resources/views/mail';
/**
* @var string the session key name to impersonate users. Please, modify it for security reasons!
*/
Expand Down
2 changes: 1 addition & 1 deletion src/User/Service/MailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct($type, $from, $to, $subject, $view, array $params, M
$this->view = $view;
$this->params = $params;
$this->mailer = $mailer;
$this->viewPath = $this->getModule()->viewPath . '/mail';
$this->viewPath = $this->getModule()->mailViewPath;
$this->mailer->setViewPath($this->viewPath);
$this->mailer->getView()->theme = Yii::$app->view->theme;
}
Expand Down
46 changes: 46 additions & 0 deletions src/User/resources/views/bootstrap3/admin/_account.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/*
* This file is part of the 2amigos/yii2-usuario project.
*
* (c) 2amigOS! <http://2amigos.us/>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

use yii\bootstrap\ActiveForm;
use yii\helpers\Html;

/** @var yii\web\View $this */
/** @var Da\User\Model\User $user */
/** @var \Da\User\Module $module */

?>

<?php $this->beginContent($module->viewPath. '/admin/update.php', ['user' => $user]) ?>

<?php $form = ActiveForm::begin(
[
'layout' => 'horizontal',
'enableAjaxValidation' => true,
'enableClientValidation' => false,
'fieldConfig' => [
'horizontalCssClasses' => [
'wrapper' => 'col-sm-9',
],
],
]
); ?>

<?= $this->render('/admin/_user', ['form' => $form, 'user' => $user]) ?>

<div class="form-group">
<div class="col-lg-offset-3 col-lg-9">
<?= Html::submitButton(Yii::t('usuario', 'Update'), ['class' => 'btn btn-block btn-success']) ?>
</div>
</div>

<?php ActiveForm::end(); ?>

<?php $this->endContent() ?>
34 changes: 34 additions & 0 deletions src/User/resources/views/bootstrap3/admin/_assignments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/*
* This file is part of the 2amigos/yii2-usuario project.
*
* (c) 2amigOS! <http://2amigos.us/>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

use Da\User\Widget\AssignmentsWidget;

/** @var yii\web\View $this */
/** @var Da\User\Model\User $user */
/** @var string[] $params */
/** @var \Da\User\Module $module */

?>

<?php $this->beginContent($module->viewPath. '/admin/update.php', ['user' => $user]) ?>

<?= yii\bootstrap\Alert::widget(
[
'options' => [
'class' => 'alert-info alert-dismissible',
],
'body' => Yii::t('usuario', 'You can assign multiple roles or permissions to user by using the form below'),
]
) ?>

<?= AssignmentsWidget::widget(['userId' => $user->id, 'params' => $params]) ?>

<?php $this->endContent() ?>
File renamed without changes.
55 changes: 55 additions & 0 deletions src/User/resources/views/bootstrap3/admin/_profile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/*
* This file is part of the 2amigos/yii2-usuario project.
*
* (c) 2amigOS! <http://2amigos.us/>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

use yii\bootstrap\ActiveForm;
use yii\helpers\Html;

/**
* @var yii\web\View $this
* @var \Da\User\Model\User $user
* @var \Da\User\Model\Profile $profile
* @var \Da\User\Module $module
*/

?>

<?php $this->beginContent($module->viewPath. '/admin/update.php', ['user' => $user]) ?>

<?php $form = ActiveForm::begin(
[
'layout' => 'horizontal',
'enableAjaxValidation' => true,
'enableClientValidation' => false,
'fieldConfig' => [
'horizontalCssClasses' => [
'wrapper' => 'col-sm-9',
],
],
]
); ?>

<?= $form->field($profile, 'name') ?>
<?= $form->field($profile, 'public_email') ?>
<?= $form->field($profile, 'website') ?>
<?= $form->field($profile, 'location') ?>
<?= $form->field($profile, 'gravatar_email') ?>
<?= $form->field($profile, 'bio')->textarea() ?>


<div class="form-group">
<div class="col-lg-offset-3 col-lg-9">
<?= Html::submitButton(Yii::t('usuario', 'Update'), ['class' => 'btn btn-block btn-success']) ?>
</div>
</div>

<?php ActiveForm::end(); ?>

<?php $this->endContent() ?>
70 changes: 70 additions & 0 deletions src/User/resources/views/bootstrap3/admin/_session-history.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

/*
* This file is part of the 2amigos/yii2-usuario project.
*
* (c) 2amigOS! <http://2amigos.us/>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

use Da\User\Widget\SessionStatusWidget;
use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
use Da\User\Model\SessionHistory;
use Da\User\Search\SessionHistorySearch;
use yii\web\View;
use yii\data\ActiveDataProvider;

/**
* @var View $this
* @var SessionHistorySearch $searchModel
* @var ActiveDataProvider $dataProvider
* @var \Da\User\Model\User $user
* @var \Da\User\Module $module
*/
?>

<?php $this->beginContent($module->viewPath. '/admin/update.php', ['user' => $user]) ?>
<div class="row">
<div class="col-xs-12">
<?= Html::a(
Yii::t('usuario', 'Terminate all sessions'),
['/user/admin/terminate-sessions', 'id' => $user->id],
[
'class' => 'btn btn-danger btn-xs pull-right',
'data-method' => 'post'
]
) ?>
</div>
</div>
<hr>

<?php Pjax::begin(); ?>

<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
'user_agent',
'ip',
[
'contentOptions' => [
'class' => 'text-nowrap',
],
'label' => Yii::t('usuario', 'Status'),
'value' => function (SessionHistory $model) {
return SessionStatusWidget::widget(['model' => $model]);
},
],
[
'attribute' => 'updated_at',
'format' => 'datetime'
],
],
]); ?>
<?php Pjax::end(); ?>

<?php $this->endContent() ?>
File renamed without changes.
Loading

0 comments on commit 3936757

Please sign in to comment.