本文整理匯總了PHP中dektrium\user\Finder::findUser方法的典型用法代碼示例。如果您正苦於以下問題:PHP Finder::findUser方法的具體用法?PHP Finder::findUser怎麽用?PHP Finder::findUser使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類dektrium\user\Finder
的用法示例。
在下文中一共展示了Finder::findUser方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: attemptEmailChange
/**
* This method attempts changing user email. If user's "unconfirmed_email" field is empty is returns false, else if
* somebody already has email that equals user's "unconfirmed_email" it returns false, otherwise returns true and
* updates user's password.
*
* @param string $code
*
* @return bool
* @throws \Exception
*/
public function attemptEmailChange($code)
{
// TODO refactor method
/** @var Token $token */
$token = $this->finder->findToken(['user_id' => $this->id, 'code' => $code])->andWhere(['in', 'type', [Token::TYPE_CONFIRM_NEW_EMAIL, Token::TYPE_CONFIRM_OLD_EMAIL]])->one();
if (empty($this->unconfirmed_email) || $token === null || $token->isExpired) {
Yii::$app->session->setFlash('danger', Yii::t('user', 'Your confirmation token is invalid or expired'));
} else {
$token->delete();
if (empty($this->unconfirmed_email)) {
Yii::$app->session->setFlash('danger', Yii::t('user', 'An error occurred processing your request'));
} elseif ($this->finder->findUser(['email' => $this->unconfirmed_email])->exists() == false) {
if ($this->module->emailChangeStrategy == Module::STRATEGY_SECURE) {
switch ($token->type) {
case Token::TYPE_CONFIRM_NEW_EMAIL:
$this->flags |= self::NEW_EMAIL_CONFIRMED;
Yii::$app->session->setFlash('success', Yii::t('user', 'Awesome, almost there. Now you need to click the confirmation link sent to your old email address'));
break;
case Token::TYPE_CONFIRM_OLD_EMAIL:
$this->flags |= self::OLD_EMAIL_CONFIRMED;
Yii::$app->session->setFlash('success', Yii::t('user', 'Awesome, almost there. Now you need to click the confirmation link sent to your new email address'));
break;
}
}
if ($this->module->emailChangeStrategy == Module::STRATEGY_DEFAULT || $this->flags & self::NEW_EMAIL_CONFIRMED && $this->flags & self::OLD_EMAIL_CONFIRMED) {
$this->email = $this->unconfirmed_email;
$this->unconfirmed_email = null;
Yii::$app->session->setFlash('success', Yii::t('user', 'Your email address has been changed'));
}
$this->save(false);
}
}
}
示例2: beforeValidate
/** @inheritdoc */
public function beforeValidate()
{
if (parent::beforeValidate()) {
if (!empty($this->Login)) {
$this->user = $this->finder->findUser(['Login' => $this->Login])->one();
/**
* Generate password
*/
$hash = Yii::$app->security->generatePasswordHash($this->Password);
////$this->Password = $this->Password . ':' . $hash;
////list($password, $hash) = explode(':', $this->Password);
// if ($this->user !== null && Yii::$app->getSecurity()->validatePassword($this->Password, $hash) ) {
// $this->user->updateAttributes(['Password' => $hash]);
// echo $this->Password . ':' . $hash. ' OK ';
// }
// exit;
}
if ($this->user === null) {
if (CardRecord::check($this->Login)) {
$card = CardRecord::findCard($this->Login);
if ($card !== null && $card->person) {
// $this->user = $card->person->ServiceCard ? $card->person : null;
$this->user = $card->person;
return true;
}
}
$this->addError('Login', \Yii::t('user', 'Invalid login or password'));
return false;
} else {
return true;
}
} else {
return false;
}
}