omniauth_callbacks_controller.rb 641 Bytes
Newer Older
Eugen Rochko's avatar
Eugen Rochko committed
1 2
# frozen_string_literal: true

Eugen Rochko's avatar
Eugen Rochko committed
3 4 5 6 7
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def all
    user = User.from_omniauth(request.env['omniauth.auth'], current_user)

    if user.persisted?
8
      reset_friend_finding_job!
Eugen Rochko's avatar
Eugen Rochko committed
9 10 11 12 13 14
      sign_in_and_redirect(user)
    else
      redirect_to root_path
    end
  end

Eugen Rochko's avatar
Eugen Rochko committed
15 16
  alias twitter  all
  alias mastodon all
Eugen Rochko's avatar
Eugen Rochko committed
17 18 19 20

  def failure
    redirect_to root_path
  end
21 22 23 24 25 26 27 28 29 30 31

  private

  def reset_friend_finding_job!
    if session[:job_id].present?
      Sidekiq::Status.cancel(session[:job_id])
      Sidekiq::Status.delete(session[:job_id])
    end

    session[:job_id] = nil
  end
Eugen Rochko's avatar
Eugen Rochko committed
32
end