Created
April 10, 2015 23:33
-
-
Save absyah/b764099d1282eec04dfd to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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 |
This file contains hidden or 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
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