2014-11-22 63 views
0

您好我剛安裝omniauth對於Facebook和谷歌在我的應用程序按照本教程:http://sourcey.com/rails-4-omniauth-using-devise-with-twitter-facebook-and-linkedin/ 這是我的OmniauthCallbacksController:如何將使用omniauth(Rails with Devise)註冊的用戶重定向到特定頁面?

class OmniauthCallbacksController < Devise::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 

      set_flash_message(:notice, :success, kind: "#{provider}".gsub(/_/," ").split[0...1].join(' ').capitalize) if is_navigational_format? 
     else 
      session["devise.#{provider}_data"] = env["omniauth.auth"] 
      redirect_to new_user_registration_url 
     end 
     end 
    } 
    end 

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

    def after_sign_in_path_for(resource) 
    #if resource.email_verified? 
     super resource 
    #else 
    # finish_signup_path(resource) 
    #end 
    end 

    # def google_oauth2 
    # raise request.env["omniauth.auth"] 
    # end 


end 

我想所有誰與Facebook或谷歌簽署了用戶重定向(不簽字請註冊一個新帳戶)到他們的用戶個人資料頁面,併發出通知,要求他們更改他們的用戶名,因爲我在註冊時將電子郵件設置爲用戶名。我怎樣才能做到這一點?

回答

1

此行之後sign_in_and_redirect @user, event: :authentication 您可以添加一個cookie值,該用戶使用omniauth註冊。

cookies[:oA] = true 

在如果cookie的值是真after_sign_in_path_for(resource)方法檢查,添加路徑username_path(resource)例如。

相關問題