[英]Devise reset password email points to the wrong controller
我包含了devise_token_auth
可以从其他地方托管的devise_token_auth
应用程序登录。 但我也希望能够直接登录我的Rails应用程序。
我的routes.rb看起来像这样:
#...
devise_for :users
namespace :api, defaults: {format: :json} do
mount_devise_token_auth_for 'User', at: 'auth'
#...
要重置密码,webapp将POST
发送到/api/auth/password
。 通过上述配置,电子邮件中用于重置密码的链接使用了错误的控制器( users/password
)。 redirect_url不会被应用,用户会看到Rails应用而非Web应用的登录表单:
http://localhost:3000/users/password/edit?redirect_url=http://localhost:8080/reset_password&reset_password_token=...
如果我在devise_for :users
行注释,则使用api/auth/password/edit
的电子邮件链接是正确的:
http://localhost:3000/api/auth/password/edit?redirect_url=http://localhost:8080/reset_password&reset_password_token=...
但是,当然,通过评论devise_for :users
我不能仅使用rails应用程序登录(在http://localhost:3000/users/sign_in
)。
设想,在其邮件模板上重设对模型的密码( reset_password_instructions.html.erb
)调用以获取url:
<p><%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %></p>
虽然最初处理的客户端意图重置密码控制器是DeviseTokenAuth::PasswordsController
,功能edit_password_url
上User
解析到由被处理的路径Devise::PasswordsController
( users/password/edit
VS api/auth/password/edit
)。
在这种情况下, 解决方案是使用其他模型:
routes.rb
#...
devise_for :users
namespace :api, defaults: {format: :json} do
mount_devise_token_auth_for 'Api::User', at: 'auth'
#...
api / user.rb
class Api::User < ActiveRecord::Base
devise :database_authenticatable, :recoverable,
:rememberable, :trackable, :validatable
include DeviseTokenAuth::Concerns::User
#...
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.