public function actionCreate() { echo "User creation tool\n"; $user = new User(); $user->setScenario('signup'); $user->username = $this->prompt('User name', ['default' => 'admin', 'required' => true]); $user->email = $this->prompt('Email', ['default' => '*****@*****.**', 'required' => true]); $user->password = $this->prompt('Password', ['default' => 'pass', 'required' => true]); $user->email_confirmed = true; if ($user->validate()) { //Create user if ($user->save()) { echo "User was successfully created. ID: ", $user->id, "\n"; } else { echo "Error while saving!\n"; } return 0; } else { echo "Errors:\n"; $errors = $user->getErrors(); foreach ($errors as $field => $fieldErrors) { foreach ($fieldErrors as $error) { echo "\t", $error, "\n"; } } return 1; } }
/** * Validates the user. */ public function validateUser() { $user = User::findByEmail($this->email); if (!$user) { $this->addError('username', Yii::t('maddoger/user', 'User with this email does not exist.')); } }
/** * Finds user by [[username]] or [[email]] * * @return User|null */ private function getUser() { if ($this->_user === false) { $this->_user = User::findByUsernameOrEmail($this->username); } return $this->_user; }
private function sendPasswordResetEmail($email) { $user = User::findOne(['status' => User::STATUS_ACTIVE, 'email' => $email]); if (!$user) { return false; } $user->password_reset_token = Yii::$app->security->generateRandomKey(); if ($user->save(false)) { return \Yii::$app->mail->compose($this->module->passwordResetTokenEmail, ['user' => $user])->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])->setTo($email)->setSubject(Yii::t('maddoger/user', 'Password reset for {name}', ['name' => \Yii::$app->name]))->send(); } return false; }
public function search($params) { $query = User::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { if (count($query->orderBy) == 0) { $query->addOrderBy('username'); } return $dataProvider; } $this->addCondition($query, 'id'); $this->addCondition($query, 'username', true); $this->addCondition($query, 'email', true); $this->addCondition($query, 'email_confirmed'); $this->addCondition($query, 'first_name', true); $this->addCondition($query, 'last_name', true); $this->addCondition($query, 'nick_name', true); $this->addCondition($query, 'patronymic', true); $this->addCondition($query, 'short_name', true); $this->addCondition($query, 'full_name', true); $this->addCondition($query, 'date_of_birth'); $this->addCondition($query, 'gender', true); $this->addCondition($query, 'facebook_uid', true); $this->addCondition($query, 'facebook_name', true); $this->addCondition($query, 'facebook_data', true); $this->addCondition($query, 'twitter_uid', true); $this->addCondition($query, 'twitter_name', true); $this->addCondition($query, 'twitter_data', true); $this->addCondition($query, 'gplus_uid', true); $this->addCondition($query, 'gplus_name', true); $this->addCondition($query, 'gplus_data', true); $this->addCondition($query, 'vk_uid', true); $this->addCondition($query, 'vk_name', true); $this->addCondition($query, 'vk_data', true); $this->addCondition($query, 'status', true); $this->addCondition($query, 'last_visit_time'); $this->addCondition($query, 'created_at'); $this->addCondition($query, 'updated_at'); $this->addCondition($query, 'avatar', true); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getUser() { return $this->hasOne(User::className(), ['id' => 'user_id']); }
</div> <div class="col-lg-3"> <?php echo $form->field($model, 'nick_name')->textInput(['maxlength' => 50]); ?> </div> </div> <div class="row"> <div class="col-lg-3"> <?php echo $form->field($model, 'date_of_birth')->textInput(['class' => 'form-control date-editor']); ?> </div> <div class="col-lg-3"> <?php echo $form->field($model, 'gender')->dropDownList(User::getGenderItems(), ['prompt' => Yii::t('maddoger/user', 'Anything')]); ?> </div> <div class="col-lg-6"></div> </div> <div class="row"> <div class="col-lg-3"> <?php echo $form->field($model, 'facebook_uid')->textInput(['maxlength' => 255]); ?> </div> <div class="col-lg-3"> <?php echo $form->field($model, 'facebook_name')->textInput(['maxlength' => 255]); ?>
/** * @return \yii\db\ActiveQuery */ public function getUsers() { return $this->hasMany(User::className(), ['id' => 'user_id'])->viaTable(User::tableName(), ['item_name' => 'name']); }
/** * 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(\Yii::t('maddoger/user', 'The requested user does not exist.')); } }
$this->params['breadcrumbs'][] = $this->title; ?> <div class="user-view"> <p> <?php echo Html::a(Yii::t('maddoger/user', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']); ?> <?php echo Html::a(Yii::t('maddoger/user', 'Delete'), ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data-confirm' => Yii::t('maddoger/user', 'Are you sure to delete this item?'), 'data-method' => 'post']); ?> </p> <?php $all = AuthItem::find()->where(['type' => \yii\rbac\Item::TYPE_ROLE])->select(['name', 'description'])->orderBy('name')->asArray()->all(); $items = []; foreach ($all as $ar) { $items[$ar['name']] = $ar['name'] . ' - ' . $ar['description']; } //echo $form->field($model, 'rolesNames')->listBox($items, ['class'=>'form-control select2', 'multiple'=> true, 'prompt' => Yii::t('maddoger/user', 'No roles')]); $roles = '<ul class="list-unstyled">'; foreach ($model->getRolesNames() as $name) { $roles .= '<li>' . Html::encode($items[$name]) . '</li>'; } $roles .= '</ul>'; $genders = User::getGenderItems(); echo DetailView::widget(['model' => $model, 'attributes' => ['id', 'username', 'email:email', 'email_confirmed:boolean', 'last_name', 'first_name', 'patronymic', 'nick_name', 'short_name', 'full_name', 'date_of_birth:date', ['label' => Yii::t('maddoger/user', 'Gender'), 'format' => 'text', 'value' => $genders[$model->gender]], 'facebook_uid', 'facebook_name', 'facebook_data:ntext', 'twitter_uid', 'twitter_name', 'twitter_data:ntext', 'gplus_uid', 'gplus_name', 'gplus_data:ntext', 'vk_uid', 'vk_name', 'vk_data:ntext', ['label' => Yii::t('maddoger/user', 'Roles'), 'format' => 'html', 'value' => $roles], 'last_visit_time:datetime', 'created_at:datetime', 'updated_at:datetime', ['attribute' => 'avatar', 'format' => 'image', 'value' => $model->getAvatarSrc()]]]); ?> </div>
?> <?php echo $form->field($model, 'patronymic')->textInput(['maxlength' => 50]); ?> <?php echo $form->field($model, 'nick_name')->textInput(['maxlength' => 50]); ?> <?php echo $form->field($model, 'date_of_birth')->widget('maddoger\\admin\\widgets\\DateEditor'); ?> <?php echo $form->field($model, 'gender')->dropDownList(User::getGenderItems()); ?> <?php echo $form->field($model, 'avatar')->widget('maddoger\\admin\\widgets\\ImageInput', ['width' => $module->avatarWidth, 'height' => $module->avatarHeight, 'preview' => $model->getAvatarSrc()]); ?> </div> <div class="tab-pane fade" id="social"> <?php echo $form->field($model, 'facebook_uid')->textInput(['maxlength' => 255]); ?> <?php echo $form->field($model, 'facebook_name')->textInput(['maxlength' => 255]);