public function process()
 {
     if ($this->validate()) {
         $this->_user->passhash = User::hashPassword($this->password);
         return $this->_user->save();
     }
     return false;
 }
 public function actionUpdate($login)
 {
     /** @var User $user */
     $user = User::findOne(['login' => $login]);
     if ($user === null) {
         throw new Exception('User with this login not found');
     }
     $assignParam = function ($from, $to = null, $isBool = false) use($user) {
         $to = $to === null ? $from : $to;
         if ($this->{$from} !== null) {
             $user->{$to} = $isBool ? in_array($this->{$from}, ['yes', 'y', '1']) ? 1 : 0 : $this->{$from};
         }
     };
     $assignParam('login');
     $assignParam('name');
     $assignParam('email');
     $assignParam('active', 'is_active', true);
     $assignParam('superadmin', 'is_super_admin', true);
     if ($this->password !== null) {
         $user->passhash = User::hashPassword($this->password);
     }
     if ($user->save()) {
         return self::EXIT_CODE_NORMAL;
     } else {
         $this->stderr("Errors: " . Json::encode($user->getErrors()));
         return self::EXIT_CODE_ERROR;
     }
 }
Exemple #3
0
 /**
  * @return User
  */
 public function getUser()
 {
     if ($this->_user == null) {
         $this->_user = User::findByLogin($this->login);
     }
     return $this->_user;
 }
Exemple #4
0
 public function init()
 {
     if (\Yii::$app->user->isGuest) {
         return;
     }
     if (!Instance::ensure(\Yii::$app->user->identity, User::className())) {
         return;
     }
     /** @var SystemEvent[] $events */
     $this->_items = SystemEvent::find()->where(['is_viewed' => '0', 'user_id' => \Yii::$app->user->id])->orderBy(['created_at' => SORT_DESC])->all();
 }
Exemple #5
0
 /**
  * @inheritdoc
  */
 public function checkAccess($userId, $permissionName, $params = [])
 {
     if (!isset($this->_users[$userId])) {
         $this->_users[$userId] = User::findOne($userId);
     }
     $user = $this->_users[$userId];
     if ($user instanceof User && $user->is_super_admin) {
         return true;
     } else {
         return parent::checkAccess($userId, $permissionName, $params);
     }
 }
 public function actionLoginByToken($id, $token)
 {
     if (self::getAdminModule()->allowLoginViaToken == false) {
         throw new NotFoundHttpException();
     }
     /** @var User $user */
     $user = User::findOne($id);
     if ($user === null) {
         throw new NotFoundHttpException();
     }
     $token = AdminLoginToken::compareToken($user->id, $token);
     if ($token === null) {
         throw new ForbiddenHttpException();
     }
     $token->delete();
     \Yii::$app->user->login($user);
     return $this->goHome();
 }
 /**
  * @return \yii\db\ActiveRecord
  */
 public function getUser()
 {
     return $this->hasOne(User::className(), ['id' => 'user_id']);
 }
Exemple #8
0
<?php

use yii\helpers\Html;
use yz\admin\components\AfterFormRenderingEvent;
use yz\admin\widgets\ActionButtons;
use yz\admin\widgets\Box;
/**
 * @var yii\web\View $this
 * @var \yz\admin\models\User $model
 * @var \yz\admin\forms\ChangeUserPasswordForm $passwordForm
 */
$this->title = \Yii::t('admin/t', 'Update object "{item}": {title}', ['item' => \yz\admin\models\User::modelTitle(), 'title' => $model->name]);
$this->params['breadcrumbs'][] = ['label' => \yz\admin\models\User::modelTitlePlural(), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
$this->params['header'] = $this->title;
?>
<div class="user-update">

    <div class="text-right">
        <?php 
Box::begin();
?>
        <?php 
echo ActionButtons::widget(['order' => [['index', 'create', 'return']], 'addReturnUrl' => false]);
?>
        <?php 
Box::end();
?>
    </div>

    <?php 
 /**
  * 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.');
     }
 }
Exemple #10
0
<?php

use yii\helpers\Html;
use yz\admin\widgets\ActionButtons;
use yz\admin\widgets\Box;
use yz\admin\grid\GridView;
/**
 * @var yii\web\View $this
 * @var yii\data\ActiveDataProvider $dataProvider
 * @var \yz\admin\models\search\UserSearch $searchModel
 */
$this->title = \yz\admin\models\User::modelTitlePlural();
$this->params['breadcrumbs'][] = $this->title;
$this->params['header'] = $this->title;
$box = Box::begin(['cssClass' => 'box-primary']);
?>
<div class="text-right">
    <?php 
echo ActionButtons::widget(['order' => [['create', 'delete', 'return']], 'gridId' => 'user-grid', 'searchModel' => $searchModel, 'modelClass' => '\\yz\\admin\\models\\User']);
?>
</div>
<?php 
echo GridView::widget(['id' => 'user-grid', 'dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\CheckboxColumn'], 'id', 'login', 'name', 'email:email', ['attribute' => 'is_identity', 'label' => 'Является идентификатором', 'format' => 'boolean', 'visible' => \yz\admin\models\User::find()->where(['is_identity' => 1])->exists()], 'is_super_admin:boolean', 'is_active:boolean', ['label' => Yii::t('admin/t', 'Roles'), 'value' => function (\yz\admin\models\User $model) {
    return implode('; ', \yii\helpers\ArrayHelper::getColumn($model->roles, 'description'));
}], 'logged_at:datetime', 'created_at:datetime', ['class' => \yz\admin\grid\columns\ActionColumn::class, 'template' => '{update} {delete}']]]);
Box::end();
Exemple #11
0
 /**
  * @return ActiveQuery
  */
 protected function getQuery()
 {
     return User::find();
 }
Exemple #12
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUser()
 {
     return $this->hasOne(User::className(), ['id' => 'user_id'])->inverseOf('settings');
 }
Exemple #13
0
 /**
  * @return \yii\db\ActiveRecord
  */
 public function getUsers()
 {
     return $this->hasMany(User::className(), ['id' => 'user_id'])->viaTable('{{%admin_auth_assignment}}', ['item_name' => 'name']);
 }