Created
July 10, 2012 05:53
-
-
Save amitpatelx/3081430 to your computer and use it in GitHub Desktop.
OmniAuth callback controller with twitter handler
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
#app/controllers/users/omniauth_callbacks_controller.rb | |
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController | |
def twitter | |
# You need to implement the method below in your model | |
auth = env["omniauth.auth"] | |
@user = user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.new | |
if @user.persisted? | |
flash[:notice] = I18n.t "devise.omniauth_callbacks.success" | |
sign_in_and_redirect @user, :event => :authentication | |
else | |
session["devise.twitter_uid"] = auth["uid"] | |
redirect_to new_user_registration_url | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment