使用 FOS 用户包恢复密码

Password recovery with FOS User bundle

我正在尝试使用 FOSUser.Mostly 进行密码恢复,直到我尝试转到重设密码页面时一切正常。

我的电子邮件 link 是这样的:

http://localhost/yaaholidays/web/app_dev.php/en/resetting/reset/RYPuGNDgSel85v1Kcj3lrIqPRhuYt5inh3VQAOlRPgk

但是当我尝试继续时,FOS 将我重定向到

/resetting/request path

这是我的日志文件中的内容:

[2017-02-21 13:22:18] request.INFO: Matched route "fos_user_resetting_reset". {"route":"fos_user_resetting_reset","route_parameters":{"_controller":"FOS\UserBundle\Controller\ResettingController::resetAction","_locale":"en","token":"RYPuGNDgSel85v1Kcj3lrIqPRhuYt5inh3VQAOlRPgk","_route":"fos_user_resetting_reset"},"request_uri":"http://localhost/yaaholidays/web/app_dev.php/en/resetting/reset/RYPuGNDgSel85v1Kcj3lrIqPRhuYt5inh3VQAOlRPgk","method":"GET"} []

[2017-02-21 13:22:18] security.INFO: Populated the TokenStorage with an anonymous Token. [] []

[2017-02-21 13:22:18] doctrine.DEBUG: SELECT t0.username AS username_1, t0.username_canonical AS username_canonical_2, t0.email AS email_3, t0.email_canonical AS email_canonical_4, t0.enabled AS enabled_5, t0.salt AS salt_6, t0.password AS password_7, t0.last_login AS last_login_8, t0.confirmation_token AS confirmation_token_9, t0.password_requested_at AS password_requested_at_10, t0.roles AS roles_11, t0.id AS id_12, t0.salutation AS salutation_13, t0.first_name AS first_name_14, t0.surname AS surname_15, t0.phone_number AS phone_number_16, t0.profile_picture AS profile_picture_17, t0.languages AS languages_18, t0.address AS address_19, t0.agency AS agency_20 FROM fos_user t0 WHERE t0.confirmation_token = ? LIMIT 1 ["RYPuGNDgSel85v1Kcj3lrIqPRh [...]"] []

[2017-02-21 13:22:18] request.INFO: Matched route "fos_user_resetting_request". {"route":"fos_user_resetting_request","route_parameters":{"_controller":"FOS\UserBundle\Controller\ResettingController::requestAction","_locale":"en","_route":"fos_user_resetting_request"},"request_uri":"http://localhost/yaaholidays/web/app_dev.php/en/resetting/request","method":"GET"} []

[2017-02-21 13:22:18] security.INFO: Populated the TokenStorage with an anonymous Token. [] []

[2017-02-21 13:22:18] translation.WARNING: Translation not found. {"id":"Telefon","domain":"messages","locale":"en"} []

[2017-02-21 13:22:19] request.INFO: Matched route "_wdt". {"route":"_wdt","route_parameters":{"_controller":"web_profiler.controller.profiler:toolbarAction","token":"6f0aa9","_route":"_wdt","_locale":"en"},"request_uri":"http://localhost/yaaholidays/web/app_dev.php/_wdt/6f0aa9","method":"GET"} []

有人知道为什么 FOS 将我重定向到密码恢复请求页面而不是设置新密码页面吗?

通过阅读您的日志,密码重置请求似乎已过期。你的 link 过期了吗?

在控制器 FOS\UserBundle\Controller\ResettingController 中,事件 RESETTING_RESET_INITIALIZE 是在从令牌获取用户之后添加的,然后调用侦听器 ResettingListener。在此侦听器中,方法 onResettingResetInitialize(管理 RESETTING_RESET_INITIALIZE 事件)检查密码请求是否已过期并重定向到路由 fos_user_resetting_request 如果是:

/**
 * @param GetResponseUserEvent $event
 */
public function onResettingResetInitialize(GetResponseUserEvent $event)
{
    if (!$event->getUser()->isPasswordRequestNonExpired($this->tokenTtl)) {
        $event->setResponse(new RedirectResponse($this->router->generate('fos_user_resetting_request')));
    }
}

如果您刚刚收到重置密码的电子邮件并且 link 尚未过期,请检查 config.xml 中的 fosuser 配置。

如果你有这样的事情:

fos_user:
  resetting:
    token_ttl: 0

那么你的令牌ttl将永远无效。在这种情况下,例如将令牌 ttl 更改为 86400(1 天)。