Skip to content

Instantly share code, notes, and snippets.

@JulioGMedina
Created November 13, 2011 04:39
Show Gist options
  • Select an option

  • Save JulioGMedina/1361600 to your computer and use it in GitHub Desktop.

Select an option

Save JulioGMedina/1361600 to your computer and use it in GitHub Desktop.
def create
omniauth = request.env["omniauth.auth"]
authentication = Authentication.find_by_provider_and_uid_and_token(omniauth['provider'], omniauth['uid'], omniauth['credentials']['token'] )
if authentication
flash[:notice] = "Signed in successfully."
sign_in_and_redirect(:user, authentication.user)
elsif current_user
current_user.authentications.create!(:provider => omniauth['provider'], :uid => omniauth['uid'], :token => omniauth['credentials']['token'])
flash[:notice] = "Authentication successful."
redirect_to authentications_url
else
user = User.new
user.apply_omniauth(omniauth)
if user.save
flash[:notice] = "Signed in successfully."
sign_in_and_redirect(:user, user)
else
session[:omniauth] = omniauth
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