0

我正在使用 GEM 设备对来自 Facebook oauth 的用户进行身份验证。我使用以下内容创建用户

def self.find_for_facebook_oauth(auth, signed_in_resource=nil)
  user = User.where(:provider => auth.provider, :uid => auth.uid).first
  unless user
    user = User.create(name:auth.extra.raw_info.name,
                       provider:auth.provider,
                       uid:auth.uid,
                       email:auth.info.email,
                       password:Devise.friendly_token[0,20]
                       )
  end
  user
 end

然后登录:

def facebook

  @user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user)

  def after_sign_in_path_for(resource)
    return '/mypage'
  end

  if @user.persisted?
    flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Facebook"
    sign_in_and_redirect @user, :event => :authentication
  else
    session["devise.facebook_data"] = request.env["omniauth.auth"]
    redirect_to new_user_registration_url
  end
end

但是,当用户在大约 15 分钟不活动后访问应用程序时,他们将不再登录。如何增加这个时间?我目前似乎一无所获。

如果有人可以提供设置 cookie 或其他内容的详细信息,以便即使在浏览器关闭时这种情况也会持续存在,那就太好了。

编辑

完整用户.rb

class User < ActiveRecord::Base

  devise :database_authenticatable, :registerable,
       :recoverable, :rememberable, :trackable, :validatable,
       :omniauthable
  # Setup accessible (or protected) attributes for your model
  attr_accessible :name,  :provider, :uid, :email, :password, :password_confirmation, :remember_me

  has_many :ratings
  has_many :rated_recipes, :through => :ratings, :source => :recipes

  def self.find_for_facebook_oauth(auth, signed_in_resource=nil)
    user = User.where(:provider => auth.provider, :uid => auth.uid).first
    unless user
      user = User.create(name:auth.extra.raw_info.name,
                       provider:auth.provider,
                       uid:auth.uid,
                       email:auth.info.email,
                       password:Devise.friendly_token[0,20]
                       )
    end
    user
  end
end

编辑:

所以下面的一些建议让我有所收获。当您通过托管的 url 访问 rails 时,一切似乎都正常。但是,一旦您点击 facebook 应用程序页面,用户就不再保留在任何打开的选项卡中。不明白为什么会这样

4

0 回答 0