Beispiel #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;
 }
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findOne(['status' => User::STATUS_ACTIVE, 'email' => $this->email]);
     }
     return $this->_user;
 }
Beispiel #3
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByEmailOrUserName($this->email);
     }
     return $this->_user;
 }
 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;
 }
Beispiel #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUser()
 {
     return $this->hasOne(User::className(), ['id' => 'user_id']);
 }
Beispiel #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 '';
 /**
  * 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.');
 }
Beispiel #8
0
    <div class="row">
        <div class="col-xs-12 col-md-7">
            <div class="panel panel-default">
                <div class="panel-heading"><?php 
echo Yii::t('users', 'PERSONAL_INFO');
?>
</div>
                <div class="panel-body">
                    <?php 
$form = ActiveForm::begin(['id' => 'form-profile']);
?>
                    <?php 
echo $form->field($model, 'username');
?>
                    <?php 
echo $form->field($model, 'sex')->dropDownList(User::getSexArray());
?>
                    <?php 
echo $form->field($model, 'photo')->widget(Widget::className(), ['uploadUrl' => Url::toRoute('/user/user/uploadPhoto')]);
?>

                    <div class="form-group">
                        <?php 
echo Html::submitButton(Yii::t('users', 'SAVE'), ['class' => 'btn btn-primary', 'name' => 'profile-button']);
?>
                    </div>
                    <?php 
ActiveForm::end();
?>
                </div>
            </div>
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCreatedUser()
 {
     return $this->hasOne(User::className(), ['id' => 'created_user']);
 }
 public function getUser()
 {
     return User::findOne(['email' => $this->email]);
 }
Beispiel #11
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' => 'photo', 'value' => $model->photo ? $model->photo : $assets->baseUrl . '/img/' . $model->getDefaultPhoto() . '.png', '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]);
?>
Beispiel #12
0
echo $form->field($model, 'username')->textInput(['maxlength' => 255]);
?>

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

    <?php 
echo $form->field($model, 'photo')->widget(Widget::className(), ['uploadUrl' => Url::toRoute('/user/user/uploadPhoto')]);
?>

    <?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>