From 582c2fb71546fa7eac51daa681188d89256d54bc Mon Sep 17 00:00:00 2001 From: Antonio Ramirez Date: Sun, 11 Dec 2016 04:20:36 +0100 Subject: [PATCH] fixing bugs --- lib/User/AuthClient/Twitter.php | 2 +- lib/User/Bootstrap.php | 23 ++++++-- lib/User/Widget/AssignmentsWidget.php | 45 ++++++++++++++++ lib/User/Widget/form.php | 53 +++++++++++++++++++ .../resources/views/admin/_assignments.php | 2 +- lib/User/resources/views/admin/_menu.php | 12 ++--- lib/User/resources/views/security/login.php | 4 +- lib/User/resources/views/shared/message.php | 12 +---- 8 files changed, 128 insertions(+), 25 deletions(-) create mode 100644 lib/User/Widget/AssignmentsWidget.php create mode 100644 lib/User/Widget/form.php diff --git a/lib/User/AuthClient/Twitter.php b/lib/User/AuthClient/Twitter.php index 0733b3e..ebf6dd0 100644 --- a/lib/User/AuthClient/Twitter.php +++ b/lib/User/AuthClient/Twitter.php @@ -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 diff --git a/lib/User/Bootstrap.php b/lib/User/Bootstrap.php index efe5a85..64203de 100644 --- a/lib/User/Bootstrap.php +++ b/lib/User/Bootstrap.php @@ -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 * diff --git a/lib/User/Widget/AssignmentsWidget.php b/lib/User/Widget/AssignmentsWidget.php new file mode 100644 index 0000000..90e2850 --- /dev/null +++ b/lib/User/Widget/AssignmentsWidget.php @@ -0,0 +1,45 @@ +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, + ]); + } +} diff --git a/lib/User/Widget/form.php b/lib/User/Widget/form.php new file mode 100644 index 0000000..d3fad1f --- /dev/null +++ b/lib/User/Widget/form.php @@ -0,0 +1,53 @@ + + * + * 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 + */ + +?> + +updated): ?> + + [ + 'class' => 'alert-success' + ], + 'body' => Yii::t('rbac', 'Assignments have been updated'), +]) ?> + + + + false, + 'enableAjaxValidation' => false, +]) ?> + + + +field($model, 'items')->widget(Select2::className(), [ + 'data' => $model->getAvailableItems(), + 'options' => [ + 'id' => 'items', + 'multiple' => true + ], +]) ?> + + 'btn btn-success btn-block']) ?> + + + diff --git a/lib/User/resources/views/admin/_assignments.php b/lib/User/resources/views/admin/_assignments.php index 08b777d..c0c0d9f 100644 --- a/lib/User/resources/views/admin/_assignments.php +++ b/lib/User/resources/views/admin/_assignments.php @@ -1,6 +1,6 @@ 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'] ], ], ], diff --git a/lib/User/resources/views/security/login.php b/lib/User/resources/views/security/login.php index 70251f1..4dc73ea 100644 --- a/lib/User/resources/views/security/login.php +++ b/lib/User/resources/views/security/login.php @@ -1,6 +1,6 @@ params['breadcrumbs'][] = $this->title;

- ['/user/security/auth'], ] diff --git a/lib/User/resources/views/shared/message.php b/lib/User/resources/views/shared/message.php index 990ef2b..6162e7b 100644 --- a/lib/User/resources/views/shared/message.php +++ b/lib/User/resources/views/shared/message.php @@ -1,17 +1,9 @@ - * - * 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;