public function mergeUserTypeConfig($config = array(), $component = '') { $userTypes =& Module::getInstance()->userTypes; if (isset($userTypes->{$component})) { if (!empty($config)) { $userTypes->{$component} = ArrayHelper::merge($config, $userTypes->{$component}); } else { $config = $userTypes->{$component}; } } return $config; }
/** * @inheritdoc */ public function init() { /** * @var Module $m */ $m = Yii::$app->getModule('user'); Module::validateConfig($this->_module); $this->attributes += ['email' => ['type' => Form::INPUT_TEXT, 'hint' => Yii::t('user', 'Please fill out your email to receive a link to reset your password')]]; $this->leftFooter = $m->button(Module::BTN_HOME, [], ['tabindex' => 1]) . $m->button(Module::BTN_NEW_USER, [], ['tabindex' => 2]); $this->rightFooter = $m->button(Module::BTN_RESET_FORM, [], ['tabindex' => 3]) . ' ' . $m->button(Module::BTN_SUBMIT_FORM, [], ['tabindex' => 0]); parent::init(); }
/** * Constructor for Login component * * @param type $config */ public function __construct($config = array(), $m = null) { if ($m === null) { $m = Yii::$app->getModule('user'); } if ($m->userTypes[$m->getUserType()]['models']) { $config = Module::mergeDefault($config, $m->userTypes[$m->getUserType()]['models']); } if (is_array($config)) { $this->models = array_replace_recursive($this->models, $config); } }
/** * Module installation action * * @return mixed */ public function actionIndex() { /** * @var Module $m * @var User $user */ $m = $this->_module; $userClass = $this->fetchModel(Module::MODEL_USER); if (isset($m->installAccessCode) && !$m->hasSuperUser()) { $model = new InstallForm(['scenario' => Module::SCN_ACCESS]); $session = Yii::$app->session; if (!isset($model->action)) { $model->action = self::SETUP; } if ($model->load(Yii::$app->request->post())) { if ($model->action === self::SETUP && $model->validate()) { $model = new InstallForm(['scenario' => Module::SCN_INSTALL]); } elseif ($model->action === Module::SCN_ACCESS && $model->validate()) { $model = new InstallForm(['scenario' => Module::SCN_INSTALL]); $model->scenario = Module::SCN_INSTALL; $model->action = Module::SCN_INSTALL; if (isset(Yii::$app->params['adminEmail'])) { $model->email = Yii::$app->params['adminEmail']; } } elseif ($model->action === Module::SCN_INSTALL) { $model->access_code = $m->installAccessCode; if ($model->validate()) { $user = new $userClass(['username' => $model->username, 'password' => $model->password, 'email' => $model->email, 'status' => Module::STATUS_SUPERUSER, 'scenario' => Module::SCN_INSTALL]); $user->setPassword($model->password); $user->generateAuthKey(); if (!$user->save()) { $session->setFlash('error', Yii::t('user', 'Error creating the superuser. Fix the following errors:<br>{errors}', ['errors' => Module::showErrors($user)])); $model->action = Module::SCN_INSTALL; $model->scenario = Module::SCN_INSTALL; } else { $session->setFlash('success', Yii::t('user', 'User module successfully installed! You have been automatically logged in as the superuser (username: <b>{username}</b>).', ['username' => $model->username])); $session->setFlash('warning', Yii::t('user', 'You should now remove the <code>installAccessCode</code> setting from user module configuration for better security.')); Yii::$app->user->login($user); $user->setLastLogin(); return $this->forward(Module::ACTION_ADMIN_VIEW, ['id' => $user->id]); } } else { $model->action = Module::SCN_ACCESS; $model->scenario = Module::SCN_ACCESS; } } } return $this->render($model->scenario, ['model' => $model, 'user' => isset($user) ? $user : null]); } return $this->safeRedirect(); }
* @var mixed $settings */ $m = Yii::$app->getModule('user'); $url = [$m->actionSettings[Module::ACTION_ADMIN_INDEX]]; $this->title = Yii::t('user', 'Manage User') . ' (' . $model->username . ')'; $this->params['breadcrumbs'][] = ['label' => Yii::t('user', 'Manage Users'), 'url' => $url]; $this->params['breadcrumbs'][] = $model->username; $list = Html::a($m->icon('list'), $url, ['class' => 'kv-action-btn', 'data-toggle' => 'tooltip', 'title' => Yii::t('user', 'View users listing')]); $editSettings = $m->getEditSettingsAdmin($model); $getKey = function ($key) use($model) { $settings = ['attribute' => $key, 'displayOnly' => true, 'format' => 'raw', 'value' => $model->{$key} ? '<samp>' . $model->{$key} . '</samp>' : null]; return $settings; }; $statusHtml = $model->getStatusHtml(); $attribs1 = [['group' => true, 'label' => $m->icon('tag') . ' ' . Yii::t('user', 'Account Details'), 'rowOptions' => ['class' => 'info']], 'id', 'username', 'email:email', ['attribute' => 'status', 'format' => 'raw', 'value' => empty($model->status_sec) ? $statusHtml : $statusHtml . ' ' . $model->getStatusSecHtml()], ['attribute' => 'created_on', 'format' => ['datetime', $m->datetimeDispFormat], 'labelColOptions' => ['style' => 'width:40%;text-align:right']]]; $attribs2 = [['group' => true, 'label' => $m->icon('time') . ' ' . Yii::t('user', 'User Log Information'), 'rowOptions' => ['class' => 'info']], ['attribute' => 'updated_on', 'format' => ['datetime', $m->datetimeDispFormat]], ['attribute' => 'last_login_ip', 'format' => 'raw', 'value' => $model->last_login_ip ? '<samp>' . $model->last_login_ip . '</samp>' : null], ['attribute' => 'last_login_on', 'value' => Module::displayAttrTime($model, 'last_login_on'), 'format' => ['datetime', $m->datetimeDispFormat], 'labelColOptions' => ['style' => 'width:40%;text-align:right']], ['attribute' => 'password_reset_on', 'value' => Module::displayAttrTime($model, 'password_reset_on'), 'format' => ['datetime', $m->datetimeDispFormat]], 'password_fail_attempts']; $attribs3 = null; if ($m->checkSettings($editSettings, 'showHiddenInfo')) { $attribs3 = [['group' => true, 'label' => $m->icon('lock') . ' ' . Yii::t('user', 'Hidden Information'), 'rowOptions' => ['class' => 'info']], $getKey('password_hash'), $getKey('auth_key'), $getKey('email_change_key'), $getKey('reset_key'), $getKey('activation_key')]; } ?> <div class="page-header"> <div class="pull-right"><?php echo AdminMenu::widget(['ui' => 'manage', 'user' => $model]); ?> </div> <h1><?php echo $this->title; ?> </h1> </div>
/** * @param array $behaviors * * @return array * @throws InvalidConfigException */ protected function mergeBehaviors($behaviors = []) { return Module::mergeDefault($this->_module->getControllerBehaviors($this->id), $behaviors); }
/** * Updates an user profile * * @param array $data the profile data attributes * * @return \yii\web\Response|null * @throws EmailException */ protected function update($data) { $event = new UpdateEvent(); $event->extract($data); $event->model->scenario = Module::SCN_PROFILE; $post = Yii::$app->request->post(); $hasProfile = $this->_module->getProfileSetting('enabled'); $emailOld = $event->model->email; $this->_module->trigger(Module::EVENT_PROFILE_UPDATE_BEGIN, $event); $transaction = static::tranInit($event); try { if ($hasProfile || isset($post['UserProfile'])) { $validate = $event->model->load($post) && $event->profile->load($post) && Model::validateMultiple([$event->model, $event->profile]); } else { $validate = $event->model->load($post) && $event->model->validate(); } if ($validate) { $timeLeft = Module::timeLeft('email change confirmation', $event->model->getEmailChangeKeyExpiry()); $emailNew = null; if ($event->model->validateEmailChange($emailOld)) { $emailNew = $event->model->email_new; } $event->model->save(); if ($hasProfile || isset($post['UserProfile'])) { $event->profile->uploadAvatar(); $event->profile->save(); } $event->flashType = 'success'; $event->message = Yii::t('user', 'The user profile was updated successfully.'); $this->_module->trigger(Module::EVENT_PROFILE_UPDATE_COMPLETE, $event); $action = $this->fetchAction(Module::ACTION_PROFILE_INDEX); self::setFlash($event); if (!$event->model->sendEmail('newemail', $timeLeft)) { throw new EmailException(Yii::t('user', 'Your email change to <b>{email}</b> could not be processed. Please contact the system administrator or try again later.', ['email' => $emailNew])); } static::tranCommit($transaction); Yii::$app->session->setFlash('info', Yii::t('user', 'Instructions to confirm the new email has been sent to your new email address <b>{email}</b>. {timeLeft}', ['email' => $emailNew, 'timeLeft' => $timeLeft])); return $this->eventRedirect($event, [$action], false); } } catch (Exception $e) { $this->handleException($e); static::tranRollback($transaction); } return null; }
echo AdminMenu::widget(['ui' => 'list', 'user' => null]); ?> </div> <h1><?php echo $this->title; ?> </h1> </div> <div id="batch-status-out"></div> <div style="width:200px;float:right;margin:-10px auto;"> <?php echo Select2::widget(['name' => 'batch-status', 'value' => '', 'data' => $m->getValidStatuses(), 'addon' => ['append' => ['content' => Html::button(Html::icon('saved'), ['class' => 'btn btn-default', 'id' => 'btn-batch-update', 'title' => Yii::t('user', 'Go!')]), 'asButton' => true]], 'options' => ['id' => 'batch-status', 'placeholder' => Yii::t('user', 'Batch update...')]]); ?> </div> <div class="clearfix"></div> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'pjax' => true, 'panel' => false, 'export' => false, 'options' => ['id' => 'user-grid'], 'columns' => [['attribute' => 'id', 'width' => '80px'], ['attribute' => 'username', 'width' => '120px', 'format' => 'raw', 'content' => function ($model) { return $model->getUserLink(); }], 'email:email', ['attribute' => 'status', 'format' => 'raw', 'hAlign' => 'center', 'content' => function ($model) { return $model->getStatusHtml(); }, 'filter' => $m->getPrimaryStatuses(), 'width' => '140px', 'filterType' => GridView::FILTER_SELECT2, 'filterWidgetOptions' => ['options' => ['placeholder' => Yii::t('user', 'Select...')], 'pluginOptions' => ['allowClear' => true]]], ['attribute' => 'status_sec', 'format' => 'raw', 'hAlign' => 'center', 'content' => function ($model) { return $model->getStatusSecHtml(); }, 'filter' => $m->getSecondaryStatuses(), 'width' => '140px', 'filterType' => GridView::FILTER_SELECT2, 'filterWidgetOptions' => ['options' => ['placeholder' => Yii::t('user', 'Select...')], 'pluginOptions' => ['allowClear' => true]]], ['attribute' => 'last_login_ip', 'format' => 'raw', 'hAlign' => 'center', 'width' => '130px', 'value' => function ($model) { return $model->last_login_ip ? '<samp>' . $model->last_login_ip . '</samp>' : null; }], ['attribute' => 'last_login_on', 'format' => ['datetime', $m->datetimeDispFormat], 'hAlign' => 'center', 'filter' => false, 'mergeHeader' => true, 'value' => function ($model) { return Module::displayAttrTime($model, 'last_login_on'); }], ['attribute' => 'created_on', 'hAlign' => 'center', 'format' => 'date', 'label' => Yii::t('user', 'Member Since'), 'filter' => false, 'mergeHeader' => true], ['class' => 'kartik\\grid\\CheckboxColumn', 'checkboxOptions' => function ($model) { if ($model->status == Module::STATUS_SUPERUSER) { return ['disabled' => 'disabled']; } }]]]);
/** * Requests password reset. * * @return string|\yii\web\Response */ public function actionRecovery() { /** * @var RecoveryForm $model * @var User $class * @var User $user */ $class = $this->fetchModel(Module::MODEL_RECOVERY); $model = new $class(); $event = new RecoveryEvent(); $event->model = $model; $this->_module->trigger(Module::EVENT_RECOVERY_BEGIN, $event); if ($model->load(Yii::$app->request->post()) && $model->validate()) { $transaction = static::tranInit($event); try { $class = $this->fetchModel(Module::MODEL_USER); $user = $class::findByEmail($model->email); $proceed = true; $expiry = $user->getResetKeyExpiry(); if (!$class::isKeyValid($user->reset_key, $expiry)) { $user->scenario = Module::SCN_RECOVERY; $user->generateResetKey(); $proceed = $user->save(); } $timeLeft = Module::timeLeft('reset', $expiry); if ($proceed && $user->sendEmail('recovery', $timeLeft)) { $event->flashType = 'success'; $event->message = Yii::t('user', 'Check your email for further instructions to reset your password. {timeLeft}', ['timeLeft' => $timeLeft]); $event->handled = false; $this->_module->trigger(Module::EVENT_RECOVERY_COMPLETE, $event); static::setFlash($event); static::tranCommit($transaction); return $this->eventRedirect($event, $this->goHome()); } else { $event->flashType = 'error'; $event->message = Yii::t('user', 'Sorry, the password cannot be reset for the email provided. Retry again later.'); $this->_module->trigger(Module::EVENT_RECOVERY_COMPLETE, $event); throw new Exception('Error resetting password'); } } catch (Exception $e) { static::tranRollback($transaction); $this->raise($e, $event); } } static::setFlash($event); return $this->display($event->viewFile ? $event->viewFile : Module::VIEW_RECOVERY, ['model' => $model]); }
/** * Initialize the model for the user module */ public function init() { Module::validateConfig($this->_module); parent::init(); }
/** * @inheritdoc */ public function init() { Module::validateConfig($this->_module); $this->_settings = $this->_module->loginSettings; parent::init(); }
/** * Generates an action button * * @param string $key the button identification key * @param array $params the parameters to pass to the button action. * @param array $config the button configuration options to override. You can additionally set the `label` or * `icon` here. * * @return string */ public function button($key, $params = [], $config = []) { $m = Module::getInstance(); $btn = ArrayHelper::getValue($this->buttons, $key, []); if (empty($btn)) { return ''; } $labelNew = ArrayHelper::remove($config, 'label', ''); $iconNew = ArrayHelper::remove($config, 'icon', ''); $label = $icon = $action = $type = ''; $options = []; $iconOptions = ['style' => 'margin-right:5px']; extract($btn); if (!empty($iconNew)) { $icon = $iconNew; } if (!empty($icon)) { Html::addCssClass($iconOptions, explode(' ', $m->icons->prefix . $icon)); $icon = Html::tag('i', '', $iconOptions); } if (!empty($labelNew)) { $label = $labelNew; } $label = $icon . $label; $options = array_replace_recursive($options, $config); if (!empty($options['disabled'])) { $action = null; } if (!empty($action)) { $action = ArrayHelper::getValue($m->actions, $action, $action); $action = Url::to([$action] + $params); return Html::a($label, $action, $options); } if (!empty($type) && $type === 'submit' || $type === 'reset') { $type .= 'Button'; } else { $type = 'button'; } return Html::$type($label, $options); }