Skip to content

Instantly share code, notes, and snippets.

@absyah
Created April 10, 2015 23:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save absyah/b764099d1282eec04dfd to your computer and use it in GitHub Desktop.
Save absyah/b764099d1282eec04dfd to your computer and use it in GitHub Desktop.
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
oauth_callback("Facebook", "facebook_data")
end
def twitter
oauth_callback("Twitter", "twitter_data")
end
def google_oauth2
oauth_callback("Google+", "google_oauth2_data")
end
private
def oauth_callback(notice_kind, session_key)
@user = User.find_for_user_oauth(request.env["omniauth.auth"])
if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => notice_kind
sign_in_and_redirect @user, :event => :authentication
else
session["devise.#{session_key}"] = request.env["omniauth.auth"]
redirect_to root_path
end
end
end
def self.find_for_user_oauth(auth)
user = User.where(email: auth.info.email).first
// ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment