【问题标题】:1 error prohibited this user from being saved: Confirmation token is invalid1 个错误禁止保存此用户:确认令牌无效
【发布时间】:2014-09-01 08:41:35
【问题描述】:

我确实在 localhost:3000 上使用确认电子邮件进行了注册。在我的 development.rb 我这样添加

config.action_mailer.default_url_options = {:host => 'localhost:3000'}
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :address => 'smtp.gmail.com',
    :port    => '587',
    :authentication => :plain,
    :user_name  => 'myemail@gmail.com',
    :password       => 'mypassword',
    :domain  => 'localhost:3000',
    :enable_starttls_auto => true
}

当我已经注册时,我打开我的电子邮件,然后在收件箱中显示消息您可以通过以下链接确认您的帐户电子邮件:确认我的帐户我点击此链接。它重定向到 localhost:3000/users/sign_in 并且我可以成功登录。但是当我再次单击收件箱中的此链接(确认我的帐户)时。它显示如下错误:

在网址中:http://localhost:3000/users/confirmation?confirmation_token=dWUeHVP_N7VzsVwvkNW5

消息错误:

Resend confirmation instructions
1 error prohibited this user from being saved:
Confirmation token is invalid

在我的电子邮件收件箱中,当我再次单击“确认我的帐户”链接时,我希望它重定向到 localhost:3000/users/sign_in。再次单击“确认我的帐户”链接时,如何重定向到 localhost:3000/users/sign_in ?请帮帮我!

【问题讨论】:

  • 你在用设计吗?
  • 是的,我正在使用设计

标签: ruby-on-rails ruby-on-rails-4


【解决方案1】:

在确认confirmation_token 变为nil 并导致此错误后,您只能使用一次确认链接。如果您想在确认已经完成的情况下将某人重定向到登录 url。然后你需要重写设计确认控制器。

def show
  self.resource = resource_class.confirm_by_token(params[:confirmation_token])
  if resource.errors.empty?
    set_flash_message(:notice, :confirmed) if is_flashing_format?
    sign_in(resource_name, resource)
    respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
  else
    redirect_to new_user_session_path
    #respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render :new }
  end
end

【讨论】:

  • 现在可以了,非常感谢您的回答。
猜你喜欢
  • 2014-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-05
  • 1970-01-01
  • 2011-04-18
  • 2019-06-07
  • 2018-03-15
相关资源
最近更新 更多