Authlogic创建没有密码的新会话

时间:2011-07-18 08:06:37

标签: ruby-on-rails ruby-on-rails-3 facebook authlogic

我正在尝试将Facebook OAuth构建到我现有的Authlogic登录系统中。我已完成OAuth部分,并存储了facebook access_token。我面临的问题是在没有用户输入密码的情况下实际登录用户(创建会话)。

  #facebook's OAuth callback
  def callback 
    access_token = client.web_server.get_access_token(params[:code], :redirect_uri => redirect_uri)
    fb_user = JSON.parse(access_token.get('/me'))  
    @user = User.find_by_facebook_id(fb_user["id"]) || User.find_by_email(fb_user["email"]) || User.new
    @user.update_attributes({
      :facebook_id => fb_user["id"],
      :first_name => fb_user["first_name"],
      :last_name => fb_user["last_name"],
      :gender => fb_user["gender"],
      :email => fb_user["email"],
      :timezone => fb_user["timezone"],
      :locale => fb_user["locale"],
      :facebook_url => fb_user["link"],
      :facebook_access_token => access_token.token
    }) #unless @user.updated_at < 2.days.ago

# TODO: set current_user
# Maybe something like this?
   # @user_session = UserSession.new({
   #    :remember_me => true,
   #    :password =>"[FILTERED]",
   #    :email => email
   # }).save



  flash[:success] = "Welcome, #{@user.name}"
  redirect_to :root
end  

1 个答案:

答案 0 :(得分:2)

没关系我弄清楚了。它一直在自述文件中。

UserSession.new(@ user,true)// true =持久会话