0

I am using a GEM device to authenticate user from Facebook oauth. I use the following to create a user

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

and then to login:

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

However when the user visits the app after about 15 minutes of inactivity they will no longer be logged in. How can I increase this time? I don't seem to be getting anywhere currently.

If anyone could provide details of setting a cookie or something so that this will persist even when the browser is closed that would be good to.

EDIT

Full user.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

EDIT:

So some of the advice below has got me somewhere. It all seems to work fine when you access the rails via the url it is hosted at. However as soon as you hit the facebook app page the user no longer persists in any of the tabs open. Can't see why this would be

4

0 に答える 0