debshots/app/controllers/users/omniauth_callbacks_controller.rb

30 lines
818 B
Ruby

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
# Workaround for https://github.com/plataformatec/devise/issues/2432
skip_before_filter :verify_authenticity_token
def launchpad
login_via 'Launchpad'
end
def stackexchange
login_via 'StackExchange'
end
def login_via(provider_name)
# You need to implement the method below in your model (e.g. app/models/user.rb)
@user = User.from_omniauth(request.env["omniauth.auth"])
if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => provider_name
sign_in_and_redirect @user, :event => :authentication
else
redirect_to new_user_session_url, alert: @user.errors.full_messages.join("\n")
end
end
def failure
redirect_to root_path
end
end