本文整理汇总了PHP中dektrium\user\Finder::findToken方法的典型用法代码示例。如果您正苦于以下问题:PHP Finder::findToken方法的具体用法?PHP Finder::findToken怎么用?PHP Finder::findToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dektrium\user\Finder
的用法示例。
在下文中一共展示了Finder::findToken方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionReset
/**
* Displays page where user can reset password.
*
* @param int $id
* @param string $code
*
* @return string
* @throws \yii\web\NotFoundHttpException
*/
public function actionReset($id, $code)
{
if (!$this->module->enablePasswordRecovery) {
throw new NotFoundHttpException();
}
/** @var Token $token */
$token = $this->finder->findToken(['user_id' => $id, 'code' => $code, 'type' => Token::TYPE_RECOVERY])->one();
$event = $this->getResetPasswordEvent($token);
$this->trigger(self::EVENT_BEFORE_TOKEN_VALIDATE, $event);
if ($token === null || $token->isExpired || $token->user === null) {
$this->trigger(self::EVENT_AFTER_TOKEN_VALIDATE, $event);
Yii::$app->session->setFlash('danger', Yii::t('user', 'Recovery link is invalid or expired. Please try requesting a new one.'));
return $this->render('/message', ['title' => Yii::t('user', 'Invalid or expired link'), 'module' => $this->module]);
}
/** @var RecoveryForm $model */
$model = Yii::createObject(['class' => RecoveryForm::className(), 'scenario' => 'reset']);
$event->setForm($model);
$this->performAjaxValidation($model);
$this->trigger(self::EVENT_BEFORE_RESET, $event);
if ($model->load(Yii::$app->getRequest()->post()) && $model->resetPassword($token)) {
$this->trigger(self::EVENT_AFTER_RESET, $event);
return $this->render('/message', ['title' => Yii::t('user', 'Password has been changed'), 'module' => $this->module]);
}
return $this->render('reset', ['model' => $model]);
}
示例2: 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)
{
/** @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'));
} else {
if (static::find()->where(['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);
}
}
}
}
示例3: actionReset
/**
* Displays page where user can reset password.
* @param integer $id
* @param string $code
* @return string
* @throws \yii\web\NotFoundHttpException
*/
public function actionReset($id, $code)
{
if (!$this->module->enablePasswordRecovery) {
throw new NotFoundHttpException();
}
/** @var Token $token */
$token = $this->finder->findToken(['user_id' => $id, 'code' => $code, 'type' => Token::TYPE_RECOVERY])->one();
if ($token === null || $token->isExpired || $token->user === null) {
\Yii::$app->session->setFlash('danger', \Yii::t('user', 'Recovery link is invalid or out-of-date. Please try requesting a new one.'));
return $this->render('/message', ['title' => \Yii::t('user', 'Invalid or out-of-date link'), 'module' => $this->module]);
}
$model = \Yii::createObject(['class' => RecoveryForm::className(), 'scenario' => 'reset']);
$this->performAjaxValidation($model);
if ($model->load(\Yii::$app->getRequest()->post()) && $model->resetPassword($token)) {
return $this->render('/message', ['title' => \Yii::t('user', 'Password has been changed'), 'module' => $this->module]);
}
return $this->render('reset', ['model' => $model]);
}
示例4: actionReset
/**
* Displays page where user can reset password.
*
* @param int $id
* @param string $code
*
* @return string
* @throws \yii\web\NotFoundHttpException
*/
public function actionReset($id, $code)
{
$this->layout = '@app/views/layouts/login';
if (!$this->module->enablePasswordRecovery) {
throw new NotFoundHttpException();
}
/** @var Token $token */
$token = $this->finder->findToken(['user_id' => $id, 'code' => $code, 'type' => Token::TYPE_RECOVERY])->one();
if ($token === null || $token->isExpired || $token->user === null) {
Yii::$app->session->setFlash('danger', Yii::t('user', 'Recovery link is invalid or expired. Please try requesting a new one.'));
return $this->goHome();
}
/** @var RecoveryForm $model */
$model = Yii::createObject(['class' => RecoveryForm::className(), 'scenario' => 'reset']);
$this->performAjaxValidation($model);
if ($model->load(Yii::$app->getRequest()->post()) && $model->resetPassword($token)) {
return $this->redirect('/user/login', 302);
}
return $this->render('reset', ['model' => $model]);
}