我正在努力在现有的Symfony应用程序上添加重置密码功能,因此我设法完成了一半的工作,但我一直坚持使带有令牌的URL起作用。
我通过电子邮件收到以下链接: [...] / intranet / forgot-password / 1066dc12cb38651660756e6f7b9e936a8a128371bd7d8de304
当我单击该按钮时,我得到: 找不到“ GET / forgot-password / 1066dc12cb38651660756e6f7b9e936a8a128371bd7d8de304”的路由
我的路由文件如下:
security:
encoders:
AppBundle\Entity\User: bcrypt
role_hierarchy:
ROLE_GOD: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
ROLE_ADMIN: [ROLE_MANAGE_USER, ROLE_MANAGE_CATEGORY, ROLE_MANAGE_TITLE, ROLE_MANAGE_DOCUMENT, ROLE_MANAGE_ARTICLE, ROLE_MANAGE_COURSE, ROLE_MANAGE_SAE]
providers:
our_users:
entity: { class: AppBundle\Entity\User, property: email }
firewalls:
# disables authentication for assets and the profiler
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: true
guard:
authenticators:
- app.security.login_form_authenticator
logout:
path: /logout
switch_user: ~
forgot_password:
pattern: ^/api/forgot-password
anonymous: true
reset_password:
pattern: ^/api/reset-password
anonymous: true
api:
pattern: ^/api
stateless: true
guard:
authenticators:
- lexik_jwt_authentication.jwt_token_authenticator
access_control:
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/share, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/api/forgot-password, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/api/reset-password/, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/api, roles: IS_AUTHENTICATED_FULLY }
- { path: ^/, roles: ROLE_USER}
我的路由文件如下所示:
app:
resource: "@AppBundle/Controller/"
type: annotation
coop_tilleuls_forgot_password.reset:
path: '/api/forgot-password'
defaults: { _controller: coop_tilleuls_forgot_password.controller.forgot_password:resetPasswordAction}
methods: [POST]
coop_tilleuls_forgot_password.update:
path: '/reset-password/{tokenValue}'
defaults: { _controller: coop_tilleuls_forgot_password.controller.forgot_password:updatePasswordAction}
我想念什么?
答案 0 :(得分:1)
coop_tilleuls_forgot_password.reset:
path: '/api/forgot-password'
defaults: { _controller: coop_tilleuls_forgot_password.controller.forgot_password:resetPasswordAction}
methods: [POST]
您是否要通过POST请求到达/api/forgot-password
?可能不行,将其更改为允许GET
。另外,路径也应包括{token}
。
还有一个错字。替换
- { path: ^/api/forgot-password, role: IS_AUTHENTICATED_ANONYMOUSLY }
到
- { path: ^/api/forgot-password, roles: IS_AUTHENTICATED_ANONYMOUSLY }