Created
April 5, 2015 06:37
-
-
Save guiltry/568bebef711c8c92119e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OmniauthCallbacksController < Devise::OmniauthCallbacksController | |
def self.provides_callback_for(provider) | |
class_eval %Q{ | |
def #{provider} | |
# NOTE: | |
# Extract Oauth logic to a new ruby class. | |
@user = FactoryMethod::User.create("#{provider}", env["omniauth.auth"], current_user) | |
if @user.persisted? | |
sign_in_and_redirect @user, event: :authentication | |
set_flash_message(:notice, :success, kind: "#{provider}".capitalize) if is_navigational_format? | |
else | |
session["devise.#{provider}_data"] = env["omniauth.auth"] | |
redirect_to new_user_registration_url | |
end | |
end | |
} | |
end | |
[:facebook, :google_oauth2].each do |provider| | |
provides_callback_for provider | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment