예제 #1
0
 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->attributes = $this->attributes;
         $user->status = User::STATUS_NEW;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         if ($user->save()) {
             return $user;
         }
     }
     return null;
 }
예제 #2
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByEmailOrUserName($this->email);
     }
     return $this->_user;
 }
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findOne(['status' => User::STATUS_ACTIVE, 'email' => $this->email]);
     }
     return $this->_user;
 }
예제 #4
0
 protected function findFreeUsername($username, $n = '')
 {
     $exists = User::findOne(['username' => $username . $n]);
     if ($exists) {
         $n = $n == '' ? 2 : $n + 1;
         return $this->findFreeUsername($username, $n);
     }
     return $username . $n;
 }
예제 #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUser()
 {
     return $this->hasOne(User::className(), ['id' => 'user_id']);
 }
예제 #6
0
    <h1><?php 
echo Html::encode($this->title);
?>
</h1>

    <p>
        <?php 
echo Yii::$app->user->can('userCreate') ? Html::a(Yii::t('users', 'CREATE'), ['create'], ['class' => 'btn btn-success']) : '';
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', 'username', 'email:email', ['attribute' => 'sex', 'value' => function ($data) {
    return User::getSexArray()[$data->sex];
}], ['attribute' => 'status', 'value' => function ($data) {
    return User::getStatusArray()[$data->status];
}], 'created_at:datetime', 'updated_at:datetime', ['class' => 'yii\\grid\\ActionColumn', 'template' => '{view} {update} {delete} {permissions}', 'buttons' => ['view' => function ($url, $model, $key) {
    if (!Yii::$app->user->can('userView', ['user' => $model])) {
        return '';
    }
    $options = ['title' => Yii::t('yii', 'View'), 'aria-label' => Yii::t('yii', 'View'), 'data-pjax' => '0'];
    return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, $options);
}, 'update' => function ($url, $model, $key) {
    if (!Yii::$app->user->can('userUpdate', ['user' => $model])) {
        return '';
    }
    $options = ['title' => Yii::t('yii', 'Update'), 'aria-label' => Yii::t('yii', 'Update'), 'data-pjax' => '0'];
    return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, $options);
}, 'permissions' => function ($url, $model, $key) {
    if (!Yii::$app->user->can('userPermissions', ['user' => $model])) {
        return '';
예제 #7
0
echo $form->field($model, 'photo')->widget(Widget::className(), ['uploadUrl' => Url::toRoute('/user/user/uploadPhoto')]);
?>
                </div>
            </div>
        </div>
        <div class="col-xs-12 col-md-6">
            <div><?php 
echo $form->field($model, 'username');
?>
</div>
            <div><?php 
echo $form->field($model, 'email')->input('email');
?>
</div>
            <div><?php 
echo $form->field($model, 'sex')->dropDownList(User::getSexArray());
?>
</div>
            <div><?php 
echo $form->field($model, 'password')->passwordInput();
?>
</div>
            <div><?php 
echo $form->field($model, 'password_repeat')->passwordInput();
?>
</div>
        </div>
    </div>

    <div class="form-group">
        <?php 
예제 #8
0
echo $form->field($model, 'username')->textInput(['maxlength' => 255]);
?>

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

    <?php 
echo $form->field($model, 'image')->widget(trntv\filekit\widget\Upload::className(), ['url' => ['avatar-upload'], 'maxFileSize' => 1000000, 'acceptFileTypes' => new \yii\web\JsExpression('/(\\.|\\/)(gif|jpe?g|png)$/i')]);
?>

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

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

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

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

</div>
 public function getUser()
 {
     return User::findOne(['email' => $this->email]);
 }
예제 #10
0
    <h1><?php 
echo Html::encode($this->title);
?>
</h1>

    <p>
        <?php 
echo Yii::$app->user->can('userUpdate', ['user' => $model]) ? Html::a(Yii::t('yii', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) : '';
?>
        <?php 
echo Yii::$app->user->can('userDelete') ? Html::a(Yii::t('yii', 'Delete'), ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'), 'method' => 'post']]) : '';
?>
    </p>

    <?php 
echo DetailView::widget(['model' => $model, 'attributes' => ['id', 'username', 'email:email', ['attribute' => 'image_base_url', 'label' => Yii::t('users', 'PHOTO'), 'value' => $model->image_base_url && $model->image_path ? $model->image_base_url . '/' . $model->image_path : null, 'format' => ['image', ['width' => 200, 'height' => 200]]], ['attribute' => 'sex', 'value' => User::getSexArray()[$model->sex]], ['attribute' => 'status', 'value' => User::getStatusArray()[$model->status]], 'created_at:datetime', 'updated_at:datetime']]);
?>

    <h2><?php 
echo Yii::t('users', 'USER_PERMISSIONS');
?>
</h2>
    <p>
        <?php 
echo Yii::$app->user->can('userPermissions', ['user' => $model]) ? Html::a(Yii::t('yii', 'Update'), ['permissions', 'id' => $model->id], ['class' => 'btn btn-primary']) : '';
?>
    </p>

    <?php 
echo PermissionsTreeWidget::widget(['user' => $model]);
?>
예제 #11
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 ($this->_model === false) {
         $this->_model = User::findOne($id);
     }
     if ($this->_model !== null) {
         return $this->_model;
     }
     throw new NotFoundHttpException('The requested page does not exist.');
 }