更新:已回答此问题(请参阅下文)。如果有人能在未来受益,我会留下来。Authlogic发送错误的激活码
我试图让电子邮件确认上Authlogic工作使用Rails 3 http://github.com/matthooks/authlogic-activation-tutorial
认证工作,并正在产生和发送的激活邮件,每片含易腐令牌,但易腐标记不正确,因为它们与保存在用户记录中的不一致。
在按照电子邮件的道理,我得到的:异常的ActivationsController#创建
注:当我手动从表中输入正确的标记到URL,它验证,并为它应该重定向至。因此,唯一的问题是正在生成的易腐标记与正在保存的标记不同。
# UserMailer
class UserMailer < ActionMailer::Base
default :from => "[email protected]"
def registration_confirmation(user)
@user = user
mail(:to => "#{user.login} <#{user.email}>", :subject => "Registered")
end
def activation_instructions(user)
subject "Activate Your Account"
from "[email protected]"
recipients user.email
sent_on Time.now
body :account_activation_url => activate_url(user.perishable_token)
end
def welcome(user)
subject "Welcome to the site!"
from "[email protected]"
recipients user.email
sent_on Time.now
body :root_url => root_url
end
end
# E-mail itself:
To activate, click here: <%= @account_activation_url %>
的错误发生在第5行,其中的系统尝试与失败时,令牌找到用户:
class ActivationsController < ApplicationController
before_filter :require_no_user
def create
@user = User.find_by_perishable_token(params[:activation_code], 1.week) || (raise Exception)
raise Exception if @user.active?
if @user.activate!
flash[:notice] = "Your account has been activated!"
UserSession.create(@user, false) # Log user in manually
@user.deliver_welcome!
redirect_to home_url
else
render :controller => "welcome", :action => "linklogin"
end
end
end