我的User.rb:
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,:confirmable,:token_authenticatable,
:recoverable, :rememberable, :trackable, :validatable, :authentication_keys => [:name]我的路线:
devise_for :users, :controllers => { :sessions => "sessions", :confirmations => "confirmations", :passwords => "passwords", :registrations => "registrations" }我的ConfirmationsController是一个标准控制器,但具有不同的重定向。
我的电子邮件上有这样的链接:
/users/confirmation?confirmation_token=167bad44a15e02b0bd570b51e1bf927b88368d8855d92b9833a24017a2bad4be在数据库中,用户有
confirmation_token:167bad44a15e02b0bd570b51e1bf927b88368d8855d92b9833a24017a2bad4be但是,当我单击该链接时,我只看到以下页面:
Resend confirmation instructions
Confirmation token is invalid我不做的事--我还得做些什么。
CONFIRMATIONCONTROLLER:
def resource_params
params.require(:user).permit(:confirmation_token)
end
private :resource_params
def show
self.resource = resource_class.confirm_by_token(params[:confirmation_token])
if resource.errors.empty?
set_flash_message(:notice, :confirmed) if is_navigational_format?
sign_in(resource_name, resource)
session['new_user'] = true
respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
else
respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render :new }
end
end
protected
# The path used after resending confirmation instructions.
def after_resending_confirmation_instructions_path_for(resource_name)
new_registration_path(resource_name)
end我说“标准控制器”是因为当我删除它而不使用自定义控制器时,问题是相同的。
发布于 2013-08-23 00:16:57
你用的是哪种版本的设计?如果您使用的是3.1.0或更高版本,则预期此行为如下:
存储在数据库中的令牌不应该与您在确认电子邮件中发送的令牌匹配。请参阅设计/库/设计/模型/可确认的.lib,它现在包含以下内容:
def confirm_by_token(confirmation_token)
original_token = confirmation_token
confirmation_token = Devise.token_generator.digest(self, :confirmation_token, confirmation_token)
confirmable = find_or_initialize_with_error_by(:confirmation_token, confirmation_token)如您所见,通过查询字符串params传入的令牌由Devise.token_generator使用,该操作的结果将与数据库中的令牌进行比较,以发现用户记录。
看起来暂时有可能(在3.1中,但不是3.2中)通过设置
config.allow_insecure_token_lookup = true在你设计的初始化器中。但是,默认行为已被更改,以使设计更加安全。有关Design3.1中安全性改进的完整概要,请参阅这篇博客文章,包括此更改。
发布于 2014-05-06 01:43:29
您可以使用下面的解决方案(设置config.allow_insecure_token_lookup = true),但根据设计变更,这只能暂时使用。
问题的出现可能是因为您运行了Design生成器,以便在他们进行这些更改之前将所有视图转储回您的视图中。然后你更新了你的设计创业板,所有后端的东西都改变了,但是你的观点没有改变。现在,你所有与设计相关的视图和邮件都过时了,不能使用新的标记样式了。
你可以在:https://github.com/plataformatec/devise/tree/master/app/views/devise/mailer看到新的电子邮件。主要的变化是改变了这一行:
<p><%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %></p>至
<p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p>主要的区别是@resource.confirmation_token变成了@token。
发布于 2014-07-25 03:19:19
我将@resource.confirmation_token更改为@token,然后它就能工作了。
https://stackoverflow.com/questions/18390080
复制相似问题