fixing bugs

This commit is contained in:
Antonio Ramirez
2016-12-11 04:20:36 +01:00
parent 0834ad6ca0
commit 582c2fb715
8 changed files with 128 additions and 25 deletions

View File

@ -4,7 +4,7 @@ namespace Da\User\AuthClient;
use Da\User\Contracts\AuthClientInterface;
class Twitter extends \dektrium\user\clients\Twitter implements AuthClientInterface
class Twitter extends \yii\authclient\clients\Twitter implements AuthClientInterface
{
/**
* @return string

View File

@ -20,6 +20,7 @@ class Bootstrap implements BootstrapInterface
*/
public function bootstrap($app)
{
if ($app->hasModule('user') && $app->getModule('user') instanceof Module) {
$map = $this->buildClassMap($app->getModule('user')->classMap);
$this->initContainer($map);
@ -27,6 +28,7 @@ class Bootstrap implements BootstrapInterface
$this->initMailServiceConfiguration($app, $app->getModule('user'));
if ($app instanceof WebApplication) {
$this->initControllerNamespace($app);
$this->initUrlRoutes($app);
$this->initAuthCollection($app);
} else {
@ -44,6 +46,8 @@ class Bootstrap implements BootstrapInterface
protected function initContainer($map)
{
$di = Yii::$container;
try{
// events
$di->set(Event\FormEvent::class);
@ -65,9 +69,6 @@ class Bootstrap implements BootstrapInterface
$di->set(Helper\GravatarHelper::class);
$di->set(Helper\SecurityHelper::class);
// search class
$di->set(Search\UserSearch::class, [$di->get(Query\UserQuery::class)]);
// services
$di->set(Service\AccountConfirmationService::class);
$di->set(Service\EmailChangeService::class);
@ -105,6 +106,9 @@ class Bootstrap implements BootstrapInterface
}
$di->setSingleton(ClassMapHelper::class, ClassMapHelper::class, [$modelClassMap]);
// search class
$di->set(Search\UserSearch::class, [$di->get(Query\UserQuery::class)]);
if (php_sapi_name() !== 'cli') {
// override Yii
$di->set(
@ -116,6 +120,9 @@ class Bootstrap implements BootstrapInterface
]
);
}
}catch(Exception $e) {
die($e);
}
}
/**
@ -198,6 +205,16 @@ class Bootstrap implements BootstrapInterface
$app->getModule('user')->controllerNamespace = 'Da\User\Command';
}
/**
* Registers controllers
*
* @param WebApplication $app
*/
protected function initControllerNamespace(WebApplication $app)
{
$app->getModule('user')->controllerNamespace = 'Da\User\Controller';
}
/**
* Builds class map according to user configuration
*

View File

@ -0,0 +1,45 @@
<?php
namespace Da\User\Widget;
use dektrium\rbac\components\DbManager;
use dektrium\rbac\models\Assignment;
use Yii;
use yii\base\InvalidConfigException;
use yii\base\Widget;
class AssignmentsWidget extends Widget
{
/** @var integer ID of the user to whom auth items will be assigned. */
public $userId;
/** @var DbManager */
protected $manager;
/** @inheritdoc */
public function init()
{
parent::init();
$this->manager = Yii::$app->authManager;
if ($this->userId === null) {
throw new InvalidConfigException('You should set ' . __CLASS__ . '::$userId');
}
}
/** @inheritdoc */
public function run()
{
$model = Yii::createObject([
'class' => Assignment::className(),
'user_id' => $this->userId,
]);
if ($model->load(\Yii::$app->request->post())) {
$model->updateAssignments();
}
return $this->render('form', [
'model' => $model,
]);
}
}

53
lib/User/Widget/form.php Normal file
View File

@ -0,0 +1,53 @@
<?php
/*
* This file is part of the Dektrium project
*
* (c) Dektrium project <http://github.com/dektrium>
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
use dektrium\rbac\models\Assignment;
use kartik\select2\Select2;
use yii\bootstrap\Alert;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/**
* @var $model Assignment
*/
?>
<?php if ($model->updated): ?>
<?= Alert::widget([
'options' => [
'class' => 'alert-success'
],
'body' => Yii::t('rbac', 'Assignments have been updated'),
]) ?>
<?php endif ?>
<?php $form = ActiveForm::begin([
'enableClientValidation' => false,
'enableAjaxValidation' => false,
]) ?>
<?= Html::activeHiddenInput($model, 'user_id') ?>
<?= $form->field($model, 'items')->widget(Select2::className(), [
'data' => $model->getAvailableItems(),
'options' => [
'id' => 'items',
'multiple' => true
],
]) ?>
<?= Html::submitButton(Yii::t('rbac', 'Update assignments'), ['class' => 'btn btn-success btn-block']) ?>
<?php ActiveForm::end() ?>

View File

@ -1,6 +1,6 @@
<?php
use dektrium\rbac\widgets\Assignments;
use AssignmentsWidget;
/**
* @var yii\web\View $this

View File

@ -17,13 +17,11 @@ use yii\bootstrap\Nav;
],
[
'label' => Yii::t('user', 'Roles'),
'url' => ['/rbac/role/index'],
'visible' => isset(Yii::$app->extensions['dektrium/yii2-rbac']),
'url' => ['/rbac/role/index']
],
[
'label' => Yii::t('user', 'Permissions'),
'url' => ['/rbac/permission/index'],
'visible' => isset(Yii::$app->extensions['dektrium/yii2-rbac']),
'url' => ['/rbac/permission/index']
],
[
'label' => Yii::t('user', 'Create'),
@ -34,13 +32,11 @@ use yii\bootstrap\Nav;
],
[
'label' => Yii::t('user', 'New role'),
'url' => ['/rbac/role/create'],
'visible' => isset(Yii::$app->extensions['dektrium/yii2-rbac']),
'url' => ['/rbac/role/create']
],
[
'label' => Yii::t('user', 'New permission'),
'url' => ['/rbac/permission/create'],
'visible' => isset(Yii::$app->extensions['dektrium/yii2-rbac']),
'url' => ['/rbac/permission/create']
],
],
],

View File

@ -1,6 +1,6 @@
<?php
use dektrium\user\widgets\Connect;
use Da\User\Widget\ConnectWidget;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
@ -78,7 +78,7 @@ $this->params['breadcrumbs'][] = $this->title;
<?= Html::a(Yii::t('user', 'Don\'t have an account? Sign up!'), ['/user/registration/register']) ?>
</p>
<?php endif ?>
<?= Connect::widget(
<?= ConnectWidget::widget(
[
'baseAuthUrl' => ['/user/security/auth'],
]

View File

@ -1,17 +1,9 @@
<?php
/*
* This file is part of the Dektrium project.
*
* (c) Dektrium project <http://github.com/dektrium>
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
/**
* @var yii\web\View $this
* @var dektrium\user\Module $module
* @var \Da\User\Module $module
* @var string $title
*/
$this->title = $title;