/**
  * @param bool $performValidation
  *
  * @return bool
  */
 public function updatePassword($performValidation = true)
 {
     if ($performValidation and !$this->validate()) {
         return false;
     }
     $this->user->password = $this->password;
     $this->user->removeConfirmationToken();
     return $this->user->save();
 }
 /**
  * @param bool $performValidation
  *
  * @return bool
  */
 public function sendEmail($performValidation = true)
 {
     if ($performValidation and !$this->validate()) {
         return false;
     }
     $this->user->generateConfirmationToken();
     $this->user->save(false);
     return Yii::$app->mailer->compose(Yii::$app->yee->emailTemplates['password-reset'], ['user' => $this->user])->setFrom(Yii::$app->yee->emailSender)->setTo($this->email)->setSubject(Yii::t('yee/auth', 'Password reset for') . ' ' . Yii::$app->name)->send();
 }
Beispiel #3
0
 /**
  * Hide link if user hasn't access to it
  *
  * @inheritdoc
  */
 public static function a($text, $url = null, $options = [])
 {
     if (in_array($url, [null, '', '#'])) {
         return parent::a($text, $url, $options);
     }
     return User::canRoute($url) ? parent::a($text, $url, $options) : '';
 }
Beispiel #4
0
 /**
  * Finds user by [[username]]
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByUsername($this->username);
     }
     return $this->_user;
 }
 /**
  * Lists all models.
  * @return mixed
  */
 public function actionIndex()
 {
     $sourceLanguage = 'en-US';
     $languages = Yii::$app->yee->languages;
     $categories = MessageSource::getMessageCategories();
     unset($languages[$sourceLanguage]);
     $currentLanguage = Yii::$app->getRequest()->get('translation', NULL);
     $currentCategory = Yii::$app->getRequest()->get('category', NULL);
     if (!in_array($currentLanguage, array_keys($languages))) {
         $currentLanguage = NULL;
     }
     if (!in_array($currentCategory, array_keys($categories))) {
         $currentCategory = NULL;
     }
     if ($currentLanguage && $currentCategory) {
         Message::initMessages($currentCategory, $currentLanguage);
         $messageIds = MessageSource::getMessageIdsByCategory($currentCategory);
         $sourceTable = MessageSource::tableName();
         $messageTable = Message::tableName();
         $messages = Message::find()->andWhere(['IN', 'source_id', $messageIds])->andWhere(['language' => $currentLanguage])->indexBy('id')->all();
     } else {
         $messages = [];
     }
     if (User::hasPermission('updateTranslations') && Message::loadMultiple($messages, Yii::$app->request->post()) && Model::validateMultiple($messages)) {
         foreach ($messages as $message) {
             $message->save(false);
         }
         Yii::$app->session->setFlash('crudMessage', 'Your item has been updated.');
         return $this->refresh();
     }
     return $this->render('index', ['messages' => $messages, 'languages' => $languages, 'categories' => $categories, 'currentLanguage' => $currentLanguage, 'currentCategory' => $currentCategory]);
 }
Beispiel #6
0
 public function run()
 {
     if (User::hasPermission('viewMedia')) {
         $recent = MediaModel::find()->orderBy(['id' => SORT_DESC])->limit($this->recentLimit)->all();
         return $this->render('media', ['height' => $this->height, 'width' => $this->width, 'position' => $this->position, 'recent' => $recent]);
     }
 }
 /**
  * Check that there is no such username in the system
  */
 public function validateUsernameUnique()
 {
     if ($this->username) {
         $exists = User::findOne(['username' => $this->username]);
         if ($exists) {
             $this->addError('username', Yii::t('yee/auth', 'Login has been taken'));
         }
     }
 }
Beispiel #8
0
 /**
  * Check that there is no such E-mail in the system
  */
 public function validateEmailUnique()
 {
     if ($this->email) {
         $exists = User::findOne(['email' => $this->email]);
         if ($exists) {
             $this->addError('email', Yii::t('yee/auth', 'This E-mail already exists'));
         }
     }
 }
 /**
  * @param int $id User ID
  *
  * @throws \yii\web\NotFoundHttpException
  * @return string
  */
 public function actionChangePassword($id)
 {
     $model = User::findOne($id);
     if (!$model) {
         throw new NotFoundHttpException(Yii::t('yee/user', 'User not found'));
     }
     $model->scenario = 'changePassword';
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->session->setFlash('crudMessage', Yii::t('yee/auth', 'Password has been updated'));
         return $this->redirect(['change-password', 'id' => $model->id]);
     }
     return $this->renderIsAjax('changePassword', compact('model'));
 }
 protected function getRedirectPage($action, $model = null)
 {
     if (!User::hasPermission('editPosts') && $action == 'create') {
         return ['view', 'id' => $model->id];
     }
     switch ($action) {
         case 'update':
             return ['update', 'id' => $model->id];
             break;
         case 'create':
             return ['update', 'id' => $model->id];
             break;
         default:
             return parent::getRedirectPage($action, $model);
     }
 }
Beispiel #11
0
 public function run()
 {
     if (!$this->options) {
         $this->options = $this->getDefaultOptions();
     }
     if (User::hasPermission('viewPosts')) {
         $searchModel = new PostSearch();
         $formName = $searchModel->formName();
         $recentPosts = Post::find()->orderBy(['id' => SORT_DESC])->limit($this->recentLimit)->all();
         foreach ($this->options as &$option) {
             $count = Post::find()->filterWhere($option['filterWhere'])->count();
             $option['count'] = $count;
             $option['url'] = [$this->indexAction, $formName => $option['filterWhere']];
         }
         return $this->render('posts', ['height' => $this->height, 'width' => $this->width, 'position' => $this->position, 'posts' => $this->options, 'recentPosts' => $recentPosts]);
     }
 }
Beispiel #12
0
 /**
  * Check if user has access to current route
  *
  * @param Action $action the action to be executed.
  *
  * @return boolean whether the action should continue to be executed.
  */
 public function beforeAction($action)
 {
     if ($action->id == 'captcha') {
         return true;
     }
     $route = '/' . $action->uniqueId;
     if (Route::isFreeAccess($route, $action)) {
         return true;
     }
     if (Yii::$app->user->isGuest) {
         $this->denyAccess();
     }
     // If user has been deleted, then destroy session and redirect to home page
     if (!Yii::$app->user->isGuest and Yii::$app->user->identity === null) {
         Yii::$app->getSession()->destroy();
         $this->denyAccess();
     }
     // Superadmin owns everyone
     if (Yii::$app->user->isSuperadmin) {
         return true;
     }
     if (Yii::$app->user->identity and Yii::$app->user->identity->status != User::STATUS_ACTIVE) {
         Yii::$app->user->logout();
         Yii::$app->getResponse()->redirect(Yii::$app->getHomeUrl());
     }
     if (User::canRoute($route)) {
         $modelId = Yii::$app->getRequest()->getQueryParam('id');
         $modelClass = isset($this->owner->modelClass) ? $this->owner->modelClass : null;
         //Check access for owners
         if ($modelClass && YeeHelper::isImplemented($modelClass, OwnerAccess::CLASSNAME) && !User::hasPermission($modelClass::getFullAccessPermission()) && $modelId) {
             $model = $modelClass::findOne(['id' => $modelId]);
             if ($model && Yii::$app->user->identity->id == $model->{$modelClass::getOwnerField()}) {
                 return true;
             }
         } else {
             return true;
         }
     }
     if (isset($this->denyCallback)) {
         call_user_func($this->denyCallback, null, $action);
     } else {
         $this->denyAccess();
     }
     return false;
 }
Beispiel #13
0
 public function search($params)
 {
     $query = User::find();
     $query->with(['roles']);
     if (!Yii::$app->user->isSuperadmin) {
         $query->where(['superadmin' => 0]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => Yii::$app->request->cookies->getValue('_grid_page_size', 20)], 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     if ($this->gridRoleSearch) {
         $query->joinWith(['roles']);
     }
     $query->andFilterWhere(['id' => $this->id, 'superadmin' => $this->superadmin, 'status' => $this->status, Yii::$app->yee->auth_item_table . '.name' => $this->gridRoleSearch, 'registration_ip' => $this->registration_ip, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'email_confirmed' => $this->email_confirmed]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email]);
     return $dataProvider;
 }
Beispiel #14
0
 /**
  * @param array $items
  *
  * @return bool
  */
 protected function ensureVisibility(&$items)
 {
     $allVisible = false;
     foreach ($items as &$item) {
         if (isset($item['url']) and !in_array($item['url'], ['', '#']) and !isset($item['visible'])) {
             $item['visible'] = User::canRoute($item['url']);
         }
         if (isset($item['items'])) {
             // If not children are visible - make invisible this node
             if (!$this->ensureVisibility($item['items']) and !isset($item['visible'])) {
                 $item['visible'] = false;
             }
         }
         if (isset($item['label']) and (!isset($item['visible']) or $item['visible'] === true)) {
             $allVisible = true;
         }
     }
     return $allVisible;
 }
 /**
  * Lists all models.
  * @return mixed
  */
 public function actionIndex()
 {
     $modelClass = $this->modelClass;
     $searchModel = $this->modelSearchClass ? new $this->modelSearchClass() : null;
     $searchLinkModel = $this->modelLinkSearchClass ? new $this->modelLinkSearchClass() : null;
     $restrictAccess = YeeHelper::isImplemented($modelClass, OwnerAccess::CLASSNAME) && !User::hasPermission($modelClass::getFullAccessPermission());
     if ($searchModel) {
         $searchName = StringHelper::basename($searchModel::className());
         $params = Yii::$app->request->getQueryParams();
         if ($restrictAccess) {
             $params[$searchName][$modelClass::getOwnerField()] = Yii::$app->user->identity->id;
         }
         $dataProvider = $searchModel->search($params);
     } else {
         $restrictParams = $restrictAccess ? [$modelClass::getOwnerField() => Yii::$app->user->identity->id] : [];
         $dataProvider = new ActiveDataProvider(['query' => $modelClass::find()->where($restrictParams)]);
     }
     return $this->renderIsAjax('index', compact('dataProvider', 'searchModel', 'searchLinkModel'));
 }
 /**
  * @param int $id - User ID
  *
  * @return \yii\web\Response
  */
 public function actionSetRoles($id)
 {
     if (!Yii::$app->user->isSuperadmin and Yii::$app->user->id == $id) {
         Yii::$app->session->setFlash('error', Yii::t('yee/user', 'You can not change own permissions'));
         return $this->redirect(['set', 'id' => $id]);
     }
     $oldAssignments = array_keys(Role::getUserRoles($id));
     // To be sure that user didn't attempt to assign himself some unavailable roles
     $newAssignments = array_intersect(Role::getAvailableRoles(Yii::$app->user->isSuperAdmin, true), Yii::$app->request->post('roles', []));
     $toAssign = array_diff($newAssignments, $oldAssignments);
     $toRevoke = array_diff($oldAssignments, $newAssignments);
     foreach ($toRevoke as $role) {
         User::revokeRole($id, $role);
     }
     foreach ($toAssign as $role) {
         User::assignRole($id, $role);
     }
     Yii::$app->session->setFlash('crudMessage', Yii::t('yee', 'Saved'));
     return $this->redirect(['set', 'id' => $id]);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params = [])
 {
     $queryParams = Yii::$app->request->getQueryParams();
     $query = MenuLink::find()->joinWith('translations');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => -1], 'sort' => ['defaultOrder' => ['order' => SORT_ASC]]]);
     $this->load($queryParams);
     foreach ($params as $key => $value) {
         $this->{$key} = $value;
     }
     $restrictLinkAccess = YeeHelper::isImplemented(MenuLink::className(), OwnerAccess::CLASSNAME) && !User::hasPermission(MenuLink::getFullAccessPermission());
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     if ($restrictLinkAccess) {
         $query->andFilterWhere([MenuLink::getOwnerField() => Yii::$app->user->identity->id]);
     }
     $query->andWhere(['menu_id' => $this->menu_id])->andFilterWhere(['alwaysVisible' => $this->alwaysVisible])->andFilterWhere(['like', 'id', $this->id])->andWhere(['parent_id' => $this->parent_id]);
     return $dataProvider;
 }
 public function search($params)
 {
     $query = UserVisitLog::find();
     $query->joinWith(['user']);
     // Don't let non-superadmin view superadmin activity
     if (!Yii::$app->user->isSuperadmin) {
         $query->andWhere([User::tableName() . '.superadmin' => 0]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => Yii::$app->request->cookies->getValue('_grid_page_size', 20)], 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     if ($this->visit_time) {
         $tmp = explode(' - ', $this->visit_time);
         if (isset($tmp[0], $tmp[1])) {
             $query->andFilterWhere(['between', static::tableName() . '.visit_time', strtotime($tmp[0]), strtotime($tmp[1])]);
         }
     }
     $query->andFilterWhere([$this->tableName() . '.id' => $this->id]);
     $query->andFilterWhere(['like', User::tableName() . '.username', $this->user_id])->andFilterWhere(['like', static::tableName() . '.ip', $this->ip])->andFilterWhere(['like', static::tableName() . '.os', $this->os])->andFilterWhere(['like', static::tableName() . '.browser', $this->browser])->andFilterWhere(['like', static::tableName() . '.language', $this->language]);
     return $dataProvider;
 }
Beispiel #19
0
                                    <?php 
    echo $model->attributeLabels()['updated_by'];
    ?>
 :
                                </label>
                                <span><?php 
    echo $model->updatedBy->username;
    ?>
</span>
                            </div>

                            <?php 
    if (!$model->isNewRecord) {
        ?>
                                <?php 
        echo $form->field($model, 'created_by')->dropDownList(User::getUsersList());
        ?>
                            <?php 
    }
    ?>

                        <?php 
}
?>

                        <div class="form-group">
                            <?php 
if ($model->isNewRecord) {
    ?>
                                <?php 
    echo Html::submitButton(Yii::t('yee', 'Create'), ['class' => 'btn btn-primary']);
Beispiel #20
0
        <div class="help-block"></div>
    </div>
<?php 
} else {
    ?>
    <?php 
    echo Html::hiddenInput('url', $model->url);
}
?>

<?php 
echo Html::hiddenInput('id', $model->id);
?>

<?php 
if (User::hasPermission('editMedia') && $mode != 'modal') {
    ?>
    <?php 
    echo Html::submitButton(Yii::t('yee', 'Save'), ['class' => 'btn btn-primary']);
}
?>

<?php 
if ($mode == 'modal') {
    ?>
    <?php 
    echo Html::button(Yii::t('yee', 'Insert'), ['id' => 'insert-btn', 'class' => 'btn btn-primary']);
}
?>

<?php 
 /**
  * Deletes an existing model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  *
  * @param integer $id
  *
  * @return mixed
  */
 public function actionDelete($id)
 {
     $model = $this->findModel($id);
     if ($model->immutable && !User::hasPermission('updateImmutableSourceMessages')) {
         throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
     }
     $model->delete();
     Yii::$app->session->setFlash('crudMessage', 'Your item has been deleted.');
     return $this->redirect($this->getRedirectPage('delete', $model));
 }
Beispiel #22
0
    echo $form->field($model, 'email_confirmed')->checkbox();
    ?>
                        <?php 
}
?>
                        
                        <?php 
echo $form->field($model, 'skype')->textInput(['maxlength' => 64]);
?>
                        
                        <?php 
echo $form->field($model, 'phone')->textInput(['maxlength' => 24]);
?>

                        <?php 
if (User::hasPermission('bindUserToIp')) {
    ?>
                            <?php 
    echo $form->field($model, 'bind_to_ip')->textInput(['maxlength' => 255])->hint(Yii::t('yee', 'For example') . ' : 123.34.56.78, 234.123.89.78');
    ?>
                        <?php 
}
?>
                        
                    </div>
                </div>
            </div>

            <div class="panel panel-default">
                <div class="panel-body">
                    <div class="record-info">
Beispiel #23
0
</legend>
                                    <?php 
    echo Html::checkboxList('child_permissions', ArrayHelper::map($currentPermissions, 'name', 'name'), ArrayHelper::map($permissions, 'name', 'description'));
    ?>
                                </fieldset>
                                <br/>
                            </div>
                        <?php 
}
?>
                    </div>

                    <hr/>

                    <?php 
if (User::hasPermission('manageRolesAndPermissions')) {
    ?>
                        <?php 
    echo Html::submitButton(Yii::t('yee', 'Save'), ['class' => 'btn btn-primary btn-sm']);
    ?>
                    <?php 
}
?>

                    <?php 
echo Html::endForm();
?>

                </div>
            </div>
        </div>
Beispiel #24
0
 /**
  * Return created_by user instance
  *
  * @return \yii\db\ActiveQuery
  */
 public function getAuthor()
 {
     return $this->hasOne(User::className(), ['id' => 'created_by']);
 }
Beispiel #25
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUser()
 {
     return $this->hasOne(User::className(), ['id' => 'user_id']);
 }
Beispiel #26
0
                </div>

                <div class="col-sm-6 text-right">
                    <?php 
echo GridPageSize::widget(['pjaxId' => 'trip-grid-pjax']);
?>
                </div>
            </div>

            <?php 
Pjax::begin(['id' => 'trip-grid-pjax']);
?>

            <?php 
echo GridView::widget(['id' => 'trip-grid', 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'bulkActionOptions' => ['gridId' => 'trip-grid', 'actions' => [Url::to(['bulk-delete']) => Yii::t('yee', 'Delete')]], 'columns' => [['class' => 'yeesoft\\grid\\CheckboxColumn', 'options' => ['style' => 'width:10px']], ['attribute' => 'vehicle_model', 'class' => 'yeesoft\\grid\\columns\\TitleActionColumn', 'controller' => '/trip/default', 'title' => function (Trip $model) {
    $vehicle = $model->getVehicles()[$model->vehicle] . ' > ' . Html::encode($model->vehicle_model);
    return Html::a($vehicle, ['update', 'id' => $model->id], ['data-pjax' => 0]);
}, 'buttonsTemplate' => '{update} {delete}', 'options' => ['style' => 'width:260px']], 'city_from', 'city_to', ['attribute' => 'created_by', 'filter' => User::getUsersList(), 'value' => function (Trip $model) {
    return Html::a(Html::encode($model->author->username), ['/user/default/update', 'id' => $model->created_by], ['data-pjax' => 0]);
}, 'format' => 'raw', 'visible' => User::hasPermission('viewUsers')], ['class' => 'yeesoft\\grid\\columns\\StatusColumn', 'attribute' => 'type', 'optionsArray' => Trip::getTypeOptionsList(), 'options' => ['style' => 'width:60px']], ['class' => 'yeesoft\\grid\\columns\\StatusColumn', 'attribute' => 'status', 'optionsArray' => Trip::getStatusOptionsList(), 'options' => ['style' => 'width:60px']]]]);
?>

            <?php 
Pjax::end();
?>
        </div>
    </div>
</div>


 /**
  * Deactivate all selected grid items
  */
 public function actionBulkDelete()
 {
     if (Yii::$app->request->post('selection')) {
         $modelClass = $this->modelClass;
         $restrictAccess = YeeHelper::isImplemented($modelClass, OwnerAccess::CLASSNAME) && !User::hasPermission($modelClass::getFullAccessPermission());
         foreach (Yii::$app->request->post('selection', []) as $id) {
             $where = ['id' => $id];
             if ($restrictAccess) {
                 $where[$modelClass::getOwnerField()] = Yii::$app->user->identity->id;
             }
             $model = $modelClass::findOne($where);
             if ($model) {
                 $model->delete();
             }
         }
     }
 }
Beispiel #28
0
        $links = '';
        if (User::hasPermission('updateSourceMessages') && (!$message->source->immutable || User::hasPermission('updateImmutableSourceMessages'))) {
            $links .= ' ' . Html::a('<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>', ['/translation/source/update', 'id' => $message->source_id]);
        }
        ?>

                                <?php 
        echo $form->field($message, "[{$index}]translation")->label($message->source->message . $links);
        ?>

                            <?php 
    }
    ?>

                            <?php 
    if (User::hasPermission('updateSourceMessages')) {
        ?>
                                <?php 
        echo Html::submitButton(Yii::t('yee', 'Save All'), ['class' => 'btn btn-primary']);
        ?>
                            <?php 
    }
    ?>

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

                        <?php 
}
?>
Beispiel #29
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUpdatedBy()
 {
     return $this->hasOne(User::className(), ['id' => 'updated_by']);
 }
Beispiel #30
0
                <div class="col-sm-6 text-right">
                    <?php 
echo GridPageSize::widget(['pjaxId' => 'post-grid-pjax']);
?>
                </div>
            </div>

            <?php 
Pjax::begin(['id' => 'post-grid-pjax']);
?>

            <?php 
echo GridView::widget(['id' => 'post-grid', 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'bulkActionOptions' => ['gridId' => 'post-grid', 'actions' => [Url::to(['bulk-activate']) => Yii::t('yee', 'Publish'), Url::to(['bulk-deactivate']) => Yii::t('yee', 'Unpublish'), Url::to(['bulk-delete']) => Yii::t('yii', 'Delete')]], 'columns' => [['class' => 'yeesoft\\grid\\CheckboxColumn', 'options' => ['style' => 'width:10px']], ['class' => 'yeesoft\\grid\\columns\\TitleActionColumn', 'controller' => '/post/default', 'title' => function (Post $model) {
    return Html::a($model->title, ['/post/default/view', 'id' => $model->id], ['data-pjax' => 0]);
}], ['attribute' => 'created_by', 'filter' => yeesoft\models\User::getUsersList(), 'value' => function (Post $model) {
    return Html::a($model->author->username, ['/user/default/update', 'id' => $model->created_by], ['data-pjax' => 0]);
}, 'format' => 'raw', 'visible' => User::hasPermission('viewUsers'), 'options' => ['style' => 'width:180px']], ['class' => 'yeesoft\\grid\\columns\\StatusColumn', 'attribute' => 'status', 'optionsArray' => Post::getStatusOptionsList(), 'options' => ['style' => 'width:60px']], ['class' => 'yeesoft\\grid\\columns\\DateFilterColumn', 'attribute' => 'published_at', 'value' => function (Post $model) {
    return '<span style="font-size:85%;" class="label label-' . (time() >= $model->published_at ? 'primary' : 'default') . '">' . $model->publishedDate . '</span>';
}, 'format' => 'raw', 'options' => ['style' => 'width:150px']]]]);
?>

            <?php 
Pjax::end();
?>
        </div>
    </div>
</div>