2016-09-05 64 views
0

我想分開我的oauth重定向路徑。一個是Facebook和谷歌(register/info1),另一個是twitter(register/info2)。設計omniauth(oauth)sign_in和sign_up路徑設置

  1. 我的用戶在第一次註冊時會轉到register/info(1/2)頁面。用戶註冊並在下次登錄
  2. 後,他們去home/main,而不是register/info(1/2)

    after_sign_up_path_for方法omniauth_callback_controller不工作。所以,用戶總是去register/info(1/2)。 目前,我設置我的omniauth_callback_controllers.rb這樣。

類用戶:: OmniauthCallbacksController < 設計:: OmniauthCallbacksController

def self.provides_callback_for(provider) 
    class_eval %Q{ 
     def #{provider} 
     @user = User.find_for_oauth(env["omniauth.auth"], current_user) 
     if @user.persisted? 
      sign_in_and_redirect @user, event: :authentication 
     else 
      session["devise.#{provider}_data"] = env["omniauth.auth"] 
      redirect_to new_user_registration_url 
     end 
     end 
     } 
    end 


    [:twitter, :facebook, :google_oauth2].each do |provider| 
    provides_callback_for provider 
    end 



    def after_sign_in_path_for(resource) 
     auth = request.env['omniauth.auth'] 
     @identity = Identity.find_for_oauth(auth) 

     @user = User.find(current_user.id) 
     if @user.persisted? 
     if @identity.provider == "twitter" 
      register_info2_path 
     else 
      register_info1_path 
     end 
     else 
     home_main_path 
     end 
    end 

如果您有任何意見或相關文件,請讓我知道。謝謝。

回答

0

您可以設置每個策略回調路徑在omniauth.rb初始化:

例如:

Rails.application.config.middleware.use OmniAuth::Builder do 
    provider :facebook, "app_id", "password", 
     scope: 'public_profile', info_fields: 'id,name,link', display: 'popup', callback_path: '/stores/facebook_callback' 

end