更新:已回答此問題(請參閱下文)。如果有人能在未來受益,我會留下來。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