Class: Decidim::Devise::OmniauthRegistrationsController

Inherits:
Devise::OmniauthCallbacksController
  • Object
show all
Includes:
FormFactory, LocaleSwitcher, NeedsOrganization
Defined in:
app/controllers/decidim/devise/omniauth_registrations_controller.rb

Overview

This controller customizes the behaviour of Devise::Omniauthable.

Instance Method Summary collapse

Instance Method Details

#action_missing(action_name) ⇒ Object

Raises:

  • (AbstractController::ActionNotFound)


67
68
69
70
# File 'app/controllers/decidim/devise/omniauth_registrations_controller.rb', line 67

def action_missing(action_name)
  return send(:create) if devise_mapping.omniauthable? && User.omniauth_providers.include?(action_name.to_sym)
  raise AbstractController::ActionNotFound, "The action '#{action_name}' could not be found for Decidim::Devise::OmniauthCallbacksController"
end

#after_sign_in_path_for(user) ⇒ Object



47
48
49
50
51
52
53
# File 'app/controllers/decidim/devise/omniauth_registrations_controller.rb', line 47

def (user)
  if !pending_redirect?(user) && (user)
    authorizations_path
  else
    super
  end
end

#createObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/decidim/devise/omniauth_registrations_controller.rb', line 18

def create
  form_params = user_params_from_oauth_hash || params[:user]
  @form = form(OmniauthRegistrationForm).from_params(form_params)
  @form.email ||= verified_email

  CreateOmniauthRegistration.call(@form, verified_email) do
    on(:ok) do |user|
      if user.active_for_authentication?
         user, event: :authentication
        set_flash_message :notice, :success, kind: @form.provider.capitalize
      else
        expire_data_after_sign_in!
        redirect_to root_path
        flash[:notice] = t("devise.registrations.signed_up_but_unconfirmed")
      end
    end

    on(:invalid) do
      set_flash_message :notice, :success, kind: @form.provider.capitalize
      render :new
    end

    on(:error) do
      redirect_to decidim.new_user_registration_path
      set_flash_message :alert, :failure, kind: @form.provider, reason: t("decidim.devise.omniauth_registrations.create.email_already_exists")
    end
  end
end

#first_login_and_not_authorized?(user) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'app/controllers/decidim/devise/omniauth_registrations_controller.rb', line 63

def (user)
  user.is_a?(User) && user. == 1 && Decidim.authorization_handlers.any?
end

#newObject



14
15
16
# File 'app/controllers/decidim/devise/omniauth_registrations_controller.rb', line 14

def new
  @form = form(OmniauthRegistrationForm).from_params(params[:user])
end

#pending_redirect?(user) ⇒ Boolean

Calling the ‘stored_location_for` method removes the key, so in order to check if there’s any pending redirect after login I need to call this method and use the value to set a pending redirect. This is the only way to do this without checking the session directly.

Returns:

  • (Boolean)


59
60
61
# File 'app/controllers/decidim/devise/omniauth_registrations_controller.rb', line 59

def pending_redirect?(user)
  store_location_for(user, stored_location_for(user))
end