Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
app/controllers/users/omniauth_callbacks_controller.rb
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def self.provides_callback_for(*providers)
providers.each do |provider|
class_eval %{
def #{provider}
Rails.logger.warn(request.env["omniauth.auth"])
if not current_user.blank?
current_user.bind_service(request.env["omniauth.auth"])#Add an auth to existing
redirect_to edit_user_registration_path, :notice => "成功绑定了 #{provider} 帐号。"
else
@user = User.find_or_create_for_#{provider}(request.env["omniauth.auth"])
if @user.persisted?
flash[:notice] = "Signed in with #{provider.to_s.titleize} successfully."
sign_in_and_redirect @user, :event => :authentication, :notice => "登陆成功。"
else
redirect_to new_user_registration_url
end
end
end
}
end
end
provides_callback_for :slack
# This is solution for existing accout want bind Google login but current_user is always nil
# https://github.com/intridea/omniauth/issues/185
def handle_unverified_request
true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.