2010-07-15 112 views
1

我正在使用open_id_authentication插件進行登錄。我能夠正確地整合插件,並且效果很好。我想檢索額外的值,如用戶的暱稱和電子郵件,我無法檢索。我正在使用下面的代碼,但註冊字段爲空。我在這裏做的事情是否正確?使用openid檢索用戶詳細信息

def authenticate_with_open_id(identity_url, 
       :required => [ :nickname, :email ], 
       :optional => :fullname) do |result, identity_url, registration| 
      case result.status 
      when :missing 
       failed_login "Sorry, the OpenID server couldn't be found" 
      when :invalid 
       failed_login "Sorry, but this does not appear to be a valid OpenID" 
      when :canceled 
       failed_login "OpenID verification was canceled" 
      when :failed 
       failed_login "Sorry, the OpenID verification failed" 
      when :successful 
       if @current_user = User.find_by_openid_identifier(identity_url) 
       assign_registration_attributes!(registration) 

       if @current_user.save 
        successful_login 
       else 
        failed_login "Your OpenID profile registration failed: " + 
        @current_user.errors.full_messages.to_sentence 
       end 
       else 
       @current_user = User.new 
       #@current_user.email = registration[:email] 
       logger.info(registration) 
       if registration.empty? 
        logger.info("reg empty") 
       else 
        logger.info("reg not empty") 
       end 
       #assign_registration_attributes!(registration) 
       #failed_login(@current_user) 
       end 
      end 
      end 

回答

1

你所示的代碼片段,從該插件的文檔,是很老的Rails的標準。目前還不清楚這種插件或方法是否因爲它的年齡而仍然有效,並且缺乏明顯的當前支持和採用。

雖然沒有完全回答問題,但如果您願意考慮更好的支持方法,您可以看看Authlogic(Rails身份驗證中最後一項最重要的內容)。

除了Devise這是目前吸引了很多人的關注,在Rails社區似乎並不相當那裏的OpenID方面雖然看起來極好的框架。

看看教程here並且不要錯過episode從無與倫比的Railscast系列。我發現Authlogic 只是用我試過的任何東西