如何将注册 omniauth (Rails with Devise) 的用户重定向到特定页面



嗨,我只是按照本教程在我的应用程序中为 Facebook 和 Google 设置了全能身份验证:http://sourcey.com/rails-4-omniauth-using-devise-with-twitter-facebook-and-linkedin/这是我的 OmniauthCallbacksController :

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 或 google(未登录,注册新帐户)的用户重定向到他们的用户个人资料页面,并显示通知要求他们更改用户名,因为我在注册时将电子邮件设置为他们的用户名。我该怎么做?

在此

行之后sign_in_and_redirect @user, event: :authentication您可以添加此用户使用全身份验证注册的 cookie 值。

cookies[:oA] = true

例如,在after_sign_in_path_for(resource)方法中检查 cookie 的值是否为 true,添加路径username_path(resource)

最新更新