class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController

  # Workaround for https://github.com/plataformatec/devise/issues/2432
  # skip_before_filter :verify_authenticity_token

  def salsa
    login_via 'salsa.debian.org'
  end

  # def launchpad
  #   login_via 'Launchpad'
  # end

  # def stackexchange
  #   login_via 'StackExchange'
  # end

  # def google_oauth2
  #   login_via 'Google'
  # end

  # def amazon
  #   login_via 'Amazon'
  # end

  # def github
  #   login_via 'Github'
  # end

  # def failure
  #   redirect_to root_path
  # end

  def login_via(provider_name)
    # TODO: log

    # You need to implement the method below in your model (e.g. app/models/user.rb)
    @user = User.from_omniauth(request.env["omniauth.auth"])

    # Has the user uploaded screenshots while not being logged in?
    # Move the screenshots to the real account and tell the user.
    if @user.persisted?
      flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => provider_name
      auditlog "User #{@user.name}/#{@user.email} logged in via #{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

end
