Exemplo n.º 1
0
 /**
  * @param string $scenario
  * @param array $expected
  * @dataProvider getScenarioAttributes
  *
  */
 public function testScenarios($scenario, $expected)
 {
     $model = new User(['scenario' => $scenario]);
     $actual = $model->safeAttributes();
     sort($expected);
     sort($actual);
     expect('safe attributes are correct', $actual)->equals($expected);
 }
Exemplo n.º 2
0
 public function run()
 {
     $model = new User();
     $model->scenario = User::SCENARIO_UPDATE_USER;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $auth = Yii::$app->authManager;
         $role = $auth->getRole($this->role);
         $auth->assign($role, $model->getId());
         return $this->controller->redirect([$this->redirectAction]);
     } else {
         return $this->controller->render($this->view, ['model' => $model]);
     }
 }
Exemplo n.º 3
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         //$this->_user = User::findByUsername($this->username);
         $this->_user = User::find()->where("email = :email", [':email' => $this->email])->one();
     }
     return $this->_user;
 }
Exemplo n.º 4
0
 public function getContragentCod()
 {
     $user = User::findOne($this->user_id);
     if (!empty($user)) {
         return $user->cod;
     } else {
         return '(пусто)';
     }
 }
Exemplo n.º 5
0
 /**
  * @inheritdoc
  */
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         if (!empty($this->newPassword)) {
             $this->setPassword($this->newPassword);
         }
         return true;
     }
     return false;
 }
Exemplo n.º 6
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = User::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['>=', 'created_at', $this->date_from ? strtotime($this->date_from . ' 00:00:00') : null])->andFilterWhere(['<=', 'created_at', $this->date_to ? strtotime($this->date_to . ' 23:59:59') : null]);
     return $dataProvider;
 }
Exemplo n.º 7
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = User::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     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;
     }
     $query->andFilterWhere(['id' => $this->id, 'role' => $this->role, 'added' => $this->added]);
     $query->andFilterWhere(['like', 'fname', $this->fname])->andFilterWhere(['like', 'lname', $this->lname])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'pswd', $this->pswd]);
     return $dataProvider;
 }
Exemplo n.º 8
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = User::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->load($params);
     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;
     }
     $query->andFilterWhere(['id' => $this->id, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['>=', 'created_at', $this->date_from ? strtotime(date('Y-m-d 00:00:00', strtotime($this->date_from))) : null])->andFilterWhere(['<=', 'created_at', $this->date_to ? strtotime(date('Y-m-d 23:59:59', strtotime($this->date_to))) : null]);
     return $dataProvider;
 }
Exemplo n.º 9
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = User::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     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;
     }
     $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'email_confirm_token', $this->email_confirm_token])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])->andFilterWhere(['like', 'email', $this->email]);
     return $dataProvider;
 }
Exemplo n.º 10
0
 public function search($params)
 {
     $query = User::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => SORT_DESC]]);
     $this->load($params);
     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;
     }
     $query->andFilterWhere(['id' => $this->id, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email]);
     return $dataProvider;
 }
Exemplo n.º 11
0
 public function searchAdministrators($params)
 {
     $query = User::find()->where(['role' => 1]);
     $dataProvider = $this->search($params, $query);
     return $dataProvider;
 }
Exemplo n.º 12
0
 public function actionIndex()
 {
     $seasons = Season::find()->orderBy('time_update DESC')->limit(15)->all();
     $users = User::find()->orderBy('id DESC')->limit(10)->all();
     return $this->render('index', ['seasons' => $seasons, 'users' => $users]);
 }
Exemplo n.º 13
0
use app\modules\admin\Module;
use app\components\grid\SetColumn;
use kartik\date\DatePicker;
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel \app\modules\admin\models\search\UserSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Module::t('module', 'ADMIN_USERS');
$this->params['breadcrumbs'][] = ['label' => Module::t('module', 'ADMIN'), 'url' => ['default/index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="users-index">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>

    <p>
        <?php 
echo Html::a(Module::t('module', 'ADMIN_USERS_ADD'), ['create'], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => ['id', ['filter' => DatePicker::widget(['model' => $searchModel, 'attribute' => 'date_from', 'attribute2' => 'date_to', 'type' => DatePicker::TYPE_RANGE, 'separator' => '-', 'pluginOptions' => ['format' => 'yyyy-mm-dd']]), 'attribute' => 'created_at', 'format' => 'datetime', 'filterOptions' => ['style' => 'max-width: 180px']], ['class' => LinkColumn::className(), 'attribute' => 'username'], 'email:email', ['class' => SetColumn::className(), 'filter' => User::getStatusesArray(), 'attribute' => 'status', 'name' => 'statusName', 'cssCLasses' => [User::STATUS_ACTIVE => 'success', User::STATUS_WAIT => 'warning', User::STATUS_BLOCKED => 'default']], ['class' => ActionColumn::className()]]]);
?>

</div>
Exemplo n.º 14
0
 public function actionDelete()
 {
     $id = \Yii::$app->request->get('id');
     $user = new User();
     if ($user->deleteOne($id)) {
         jump_success('删除成功!');
     } else {
         jump_error($user->getFirstError(User::DELETE_EFFOR_INFO));
     }
 }
Exemplo n.º 15
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUser()
 {
     return $this->hasOne(User::className(), ['id' => 'user_id']);
 }
Exemplo n.º 16
0
 /**
  * Finds the User model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return User the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = User::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException(self::EXCEPTION_MESS);
     }
 }
Exemplo n.º 17
0
echo $form->field($model, 'username')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'email')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'newPassword')->passwordInput(['maxlength' => true]);
?>
 
    <?php 
echo $form->field($model, 'newPasswordRepeat')->passwordInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'status')->dropDownList(User::getStatusesArray());
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

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

</div>
Exemplo n.º 18
0
 /**
  * Finds the User model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return User the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = User::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 19
0
use yii\helpers\Html;
use yii\grid\GridView;
use app\modules\admin\models\User;
/* @var $this yii\web\View */
/* @var $searchModel app\modules\admin\models\UserSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('app', 'Users');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="user-index">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <p>
        <?php 
echo Html::a(Yii::t('app', 'Create User'), ['create'], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', 'created_at:datetime', 'username', 'email:email', ['filter' => User::getStatusesArray(), 'attribute' => 'status', 'value' => 'statusName'], ['class' => 'yii\\grid\\ActionColumn']]]);
?>

</div>
Exemplo n.º 20
0
        <?php 
}
?>
        <p>
            <?php 
echo Html::a("Видео", ['/admin/video/index'], ['class' => 'btn btn-primary']);
?>
        </p>

        <p>
            <?php 
echo Html::a("Фотографии", ['/admin/photocatalog/index'], ['class' => 'btn btn-primary']);
?>
        </p>
    <?php 
if (\app\modules\admin\models\User::getCurrRole() == 'admin') {
    ?>
        <p>
            <?php 
    echo Html::a("Слайдер", ['/admin/slider/index'], ['class' => 'btn btn-primary']);
    ?>
        </p>
    
        <p>
            <?php 
    echo Html::a("Реклама", ['/admin/ads/index'], ['class' => 'btn btn-primary']);
    ?>
        </p>
    <?php 
}
?>
Exemplo n.º 21
0
 /**
  * 配置用户权限组
  *
  * @return string
  */
 public function actionAssign_ment_edit()
 {
     $model = new Auth_assignment();
     if (\Yii::$app->request->isGet) {
         $user_id = \Yii::$app->request->get('user_id');
         if (!$user_id || !User::find($user_id)) {
             jump_error(t_arr('app', ['data', 'does not', 'exists'], '', '!'));
         }
         //角色列表
         $assignMents = $model->getAssignmentByUserid($user_id);
         $assignMentSelectArray = [];
         if (is_array($assignMents) && count($assignMents)) {
             foreach ($assignMents as $_key => $_value) {
                 $assignMentSelectArray[] = $_key;
             }
         }
         //所有角色{}
         $allRolesArray = $model->getAllRoles2SelectArray();
         //用户信息
         $user = User::findOne($user_id);
         return $this->render('assign_ment_edit', ['model' => $model, 'user' => $user, 'assignMentSelectArray' => $assignMentSelectArray, 'allRolesArray' => $allRolesArray]);
     } else {
         if (\Yii::$app->request->isPost) {
             $rs = $model->assign_user_create(\Yii::$app->request->post());
             if ($rs) {
                 jump_success(t_arr('app', ['update', 'success'], '', '!'));
             } else {
                 jump_error(t_arr('app', ['update', 'fail'], '', '!'));
             }
         }
     }
 }
Exemplo n.º 22
0
 public function actionLogout()
 {
     $user = new User();
     $user->logout();
     $this->goHome();
 }
Exemplo n.º 23
0
 /**
  * 更新一个用户的信息
  *
  * @param $id
  * @param $params
  * @return bool
  */
 public function updateOne($id, $params)
 {
     $model = User::findOne($id);
     $model->scenario = 'update';
     if ($model->load($params) && $model->validate()) {
         return $model->save();
     }
     return false;
 }
Exemplo n.º 24
0
</h1>
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <p>
        <?php 
echo Html::a(Yii::t('user', 'Create User'), ['create'], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', ['filter' => DatePicker::widget(['model' => $searchModel, 'attribute' => 'date_from', 'attribute2' => 'date_to', 'type' => DatePicker::TYPE_RANGE, 'separator' => '-', 'pluginOptions' => ['format' => 'dd.mm.yyyy']]), 'attribute' => 'created_at', 'format' => 'date'], ['attribute' => 'username', 'format' => 'raw', 'value' => function ($model, $key, $index, $column) {
    /** @var User $model */
    return Html::a(Html::encode($model->username), ['view', 'id' => $model->id]);
}], 'email:email', ['filter' => User::getStatusesArray(), 'attribute' => 'status', 'format' => 'raw', 'value' => function ($model, $key, $index, $column) {
    /** @var User $model */
    /** @var \yii\grid\DataColumn $column */
    $value = $model->{$column->attribute};
    switch ($value) {
        case User::STATUS_ACTIVE:
            $class = 'success';
            break;
        case User::STATUS_WAIT:
            $class = 'warning';
            break;
        case User::STATUS_BLOCKED:
        default:
            $class = 'default';
    }
    $html = Html::tag('span', Html::encode($model->getStatusName()), ['class' => 'label label-' . $class]);