本文整理汇总了PHP中app\modules\user\models\User::findOne方法的典型用法代码示例。如果您正苦于以下问题:PHP User::findOne方法的具体用法?PHP User::findOne怎么用?PHP User::findOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\modules\user\models\User
的用法示例。
在下文中一共展示了User::findOne方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUser
/**
* Finds user by [[email]]
*
* @return User|null
*/
public function getUser()
{
if ($this->_user === false) {
$this->_user = User::findOne(['email' => $this->email]);
}
return $this->_user;
}
示例2: getUser
/**
* Finds user by [[username]]
*
* @return User|null
*/
public function getUser()
{
if ($this->_user === false) {
$this->_user = User::findOne(['email' => $this->email, 'status' => User::STATUS_ACTIVE]);
}
return $this->_user;
}
示例3: getUser
public function getUser()
{
if ($this->_user === false) {
$this->_user = User::findOne(['id' => Yii::$app->user->id]);
}
return $this->_user;
}
示例4: actionListByAgent
public function actionListByAgent($id)
{
$searchModel = new OrdersSearch();
$dataProvider = $searchModel->searchListByAgent(Yii::$app->request->queryParams, $id);
$user = User::findOne($id);
return $this->render('listByAgent', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'user' => $user]);
}
示例5: findModel
/**
* @param $username
* @return null|static
* @throws Exception
*/
private function findModel($username)
{
if (!($model = User::findOne(['username' => $username]))) {
throw new Exception('User not found');
}
return $model;
}
示例6: findModel
/**
* 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 \app\modules\user\models\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.');
}
}
示例7: findModel
protected function findModel($id)
{
if (($model = Yii::$app->user->id == $id ? Yii::$app->user->identity : User::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
示例8: testChangeCorrect
public function testChangeCorrect()
{
/** @var User $user */
$user = User::findOne($this->users[0]['id']);
$form = new PasswordChangeForm($user);
$form->setAttributes(['currentPassword' => 'adminpass', 'newPassword' => 'new-password', 'newPasswordRepeat' => 'new-password']);
expect('password is changed', $form->changePassword())->true();
expect('password is correct', $user->validatePassword('new-password'))->true();
}
示例9: testUpdateCorrect
public function testUpdateCorrect()
{
/** @var User $user */
$user = User::findOne($this->users[0]['id']);
$form = new ProfileUpdateForm($user);
$form->setAttributes(['email' => 'new-email@site.com']);
expect('user is updated', $form->update())->true();
expect('email is new', $user->email)->equals('new-email@site.com');
}
示例10: findModel
/**
* Finds the User model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param string $id
* @param bool $search
* @return User|UserSearch the loaded model
* @throws NotFoundHttpException
*/
protected function findModel($id, $search = false)
{
if ($search) {
$model = new UserSearch();
} elseif (!$id) {
$model = new User();
} elseif (!($model = User::findOne($id))) {
throw new NotFoundHttpException(\Yii::t('modules/user', 'User not found'));
}
return $model;
}
示例11: resetPasword
public function resetPasword()
{
if ($user = User::findOne(['email' => $this->email])) {
$new_password = substr(Yii::$app->security->generateRandomString(), 0, 6);
$user->setPassword($new_password);
if ($user->save()) {
return \Yii::$app->mailer->compose(['html' => '@app/modules/user/mails/passwordReset'], ['username' => $user->username, 'password' => $new_password])->setFrom([\Yii::$app->params['adminEmail'] => \Yii::$app->name . ' robot'])->setTo($this->email)->setSubject('Password reset for ' . \Yii::$app->name)->send();
}
}
return false;
}
示例12: sendEmail
/**
* Sends an email with a link, for resetting the password.
*
* @return boolean whether the email was send
*/
public function sendEmail()
{
/* @var $user User */
$user = User::findOne(['status' => User::STATUS_ACTIVE, 'email' => $this->email]);
if ($user) {
$user->generatePasswordResetToken();
if ($user->save()) {
return \Yii::$app->mailer->compose('recover', ['user' => $user])->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])->setTo($this->email)->setSubject('Востановление пароля на сайте ' . \Yii::$app->name)->send();
}
}
return false;
}
示例13: sendEmail
/**
* Sends an email with a link, for resetting the password.
*
* @return boolean whether the email was send
*/
public function sendEmail()
{
/* @var $user User */
$user = User::findOne(['status' => User::S_ACTIVE, 'email' => $this->email]);
if ($user) {
$user->generatePasswordResetToken();
if ($user->save()) {
Yii::$app->mailer->compose('@app/modules/user/mails/passwordReset', ['user' => $user])->setFrom([Yii::$app->params['adminEmail'] => Yii::$app->name])->setTo($this->email)->setSubject(Yii::t('frontend', 'Password reset for {name}', ['name' => Yii::$app->name]))->send();
}
}
return false;
}
示例14: change
public function change()
{
if ($this->validate()) {
$id = Yii::$app->user->id;
$model = User::findOne(['id' => $id]);
if (!empty($model)) {
$model->setPassword($this->new_password);
return $model->save(false);
}
}
return false;
}
示例15: testSendEmailCorrectUser
public function testSendEmailCorrectUser()
{
$model = new PasswordResetRequestForm(3600);
$model->email = $this->users[0]['email'];
/** @var User $user */
$user = User::findOne(['password_reset_token' => $this->users[0]['password_reset_token']]);
expect('email sent', $model->sendEmail())->true();
expect('user has valid token', $user->password_reset_token)->notNull();
expect('message file exists', file_exists($this->getMessageFile()))->true();
$message = file_get_contents($this->getMessageFile());
expect('message file "from" is correct', $message)->contains(Yii::$app->params['supportEmail']);
expect('message file "to" is correct', $message)->contains($model->email);
}