authlogic rails app中的无限循环

时间:2010-07-08 00:43:46

标签: ruby-on-rails authlogic

我有一个使用authlogic和facebook的rails应用程序。在我第一次登录Facebook后不久,我的所有页面都停止响应并显示日志

Processing UserSessionsController#new (for [IP ADDRESS] at 2010-07-08 00:32:31) [GET]
  Parameters: {"action"=>"new", "controller"=>"user_sessions"}

SystemStackError (stack level too deep):
  (eval):5:in `connection_handler'
  authlogic (2.1.5) lib/authlogic/session/callbacks.rb:83:in `validate'
  authlogic (2.1.5) lib/authlogic/session/validation.rb:64:in `valid?'
  authlogic (2.1.5) lib/authlogic/session/cookies.rb:110:in `persist_by_cookie'
  authlogic (2.1.5) lib/authlogic/session/callbacks.rb:90:in `persist'
  authlogic (2.1.5) lib/authlogic/session/persistence.rb:55:in `persisting?'
  authlogic (2.1.5) lib/authlogic/session/persistence.rb:39:in `find'
  authlogic (2.1.5) lib/authlogic/acts_as_authentic/session_maintenance.rb:96:in `get_session_information'
  authlogic (2.1.5) lib/authlogic/acts_as_authentic/session_maintenance.rb:95:in `each'
  authlogic (2.1.5) lib/authlogic/acts_as_authentic/session_maintenance.rb:95:in `get_session_information'
  authlogic (2.1.5) lib/authlogic/session/callbacks.rb:83:in `validate'
  authlogic (2.1.5) lib/authlogic/session/validation.rb:64:in `valid?'
  authlogic (2.1.5) lib/authlogic/session/cookies.rb:110:in `persist_by_cookie'
  authlogic (2.1.5) lib/authlogic/session/callbacks.rb:90:in `persist'
  authlogic (2.1.5) lib/authlogic/session/persistence.rb:55:in `persisting?'
  authlogic (2.1.5) lib/authlogic/session/persistence.rb:39:in `find'
  authlogic (2.1.5) lib/authlogic/acts_as_authentic/session_maintenance.rb:96:in `get_session_information'
  authlogic (2.1.5) lib/authlogic/acts_as_authentic/session_maintenance.rb:95:in `each'
  authlogic (2.1.5) lib/authlogic/acts_as_authentic/session_maintenance.rb:95:in `get_session_information'

除了有更多的迭代。

这是我的routes.rb:

  map.connect ':controller/:action/:id'
  map.connect ':controller/:action/:id.:format'

  map.resource :account, :controller => "users"
  map.resources :users

  map.resource :user_session
  map.root :controller => "user_sessions", :action => "new" # optional, this just sets the root route

This post提示设置持久性令牌可能会解决问题,但这对我没有帮助。这是我的user.rb代码。它基本上是authlogic w / facebook演示的标准代码:

class User < ActiveRecord::Base
  is_gravtastic :email, :filetype => :png, :default => "identicon", :size => 120

  validates_uniqueness_of :name, :message => "should be unique!"

  def before_connect(facebook_session)
        logger.info("HEY FACEBOOK, HOW'S IT GOING? SO LOVELY TO SEE: #{facebook_session.user.name}")

        # Authlogic isn't as magic as we thought: tell it we need a persistence token, based on advice
        # in http://github.com/binarylogic/authlogic/issuesearch?state=closed&q=persistence#issue/68
        self.persistence_token = reset_persistence_token
  end

  def before_save
    if self.name.nil? || self.name.blank?
      self.name = "user#{Time.now.to_i}"
    end
  end 


  acts_as_authentic do |c| 
    c.validate_login_field = false
    # optional, but if a user registers by openid, he should at least share his email-address with the app
    c.validate_email_field = false
    c.validate_password_field = false
    # fetch email by ax
    c.openid_required_fields = [:email,"http://axschema.org/contact/email"]
    #c.openid_required_fields = [:language, "http://axschema.org/pref/language"]
  end

  def before_connect(facebook_session)
    self.name = facebook_session.user.name
    self.birthday = facebook_session.user.birthday_date
    self.about = facebook_session.user.about_me
    self.locale = facebook_session.user.locale
    #self.website = facebook_session.user.website
  end



  private

  def map_openid_registration(registration)

    if registration.empty?
      # no email returned
      self.email_autoset = false
    else
      # email by sreg
      unless registration["email"].nil? && registration["email"].blank?
        self.email = registration["email"]
        self.email_autoset = true
      else
        # email by ax
        unless registration['http://axschema.org/contact/email'].nil? && registration['http://axschema.org/contact/email'].first.blank?
          self.email = registration['http://axschema.org/contact/email'].first
          self.email_autoset = true
        else
          # registration-hash seems to contain information other than the email-address
          self.email_autoset = false
        end
      end
    end

  end

end

呀。有什么建议?提前谢谢。

1 个答案:

答案 0 :(得分:-1)

最重要的是,我建议您养成每次更改一次的习惯。这样,你就会知道哪个改变会给你带来问题。