2010-10-11 70 views
0

更新:已回答此问题(请参阅下文)。如果有人能在未来受益,我会留下来。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 

回答

0

这很有趣 - 有时自问揭示了回答这个问题的过程。

在我的用户#create中,有不同的用户类型,并且该操作在初始验证保存后设置了一对值,并在未经验证的情况下再次保存简单更改。

我的电子邮件正在第一次和第二次保存之间发送,所以当用户点击激活电子邮件时,perishable_token已被重置。

第二次保存后,我将邮件移动到了下面,现在激活电子邮件完美地工作。

非常感谢您花费在考虑此问题的任何时间。 :) Cirrus