Class: Decidim::Devise::OmniauthRegistrationsController
- Inherits:
-
Devise::OmniauthCallbacksController
- Object
- Devise::OmniauthCallbacksController
- Decidim::Devise::OmniauthRegistrationsController
- Includes:
- Decidim::DeviseControllers, FormFactory
- Defined in:
- app/controllers/decidim/devise/omniauth_registrations_controller.rb
Overview
This controller customizes the behaviour of Devise::Omniauthable.
Instance Method Summary collapse
- #action_missing(action_name) ⇒ Object
- #after_sign_in_path_for(user) ⇒ Object
- #create ⇒ Object
- #first_login_and_not_authorized?(user) ⇒ Boolean
- #new ⇒ Object
-
#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.
Instance Method Details
#action_missing(action_name) ⇒ Object
70 71 72 73 74 |
# File 'app/controllers/decidim/devise/omniauth_registrations_controller.rb', line 70 def action_missing(action_name) return send(:create) if devise_mapping.omniauthable? && current_organization.enabled_omniauth_providers.keys.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
48 49 50 51 52 53 54 55 56 |
# File 'app/controllers/decidim/devise/omniauth_registrations_controller.rb', line 48 def after_sign_in_path_for(user) if user.present? && user.blocked? check_user_block_status(user) elsif !pending_redirect?(user) && (user) decidim_verifications. else super end end |
#create ⇒ Object
14 15 16 17 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 46 |
# File 'app/controllers/decidim/devise/omniauth_registrations_controller.rb', line 14 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? sign_in_and_redirect user, event: :authentication :notice, :success, kind: @form.provider.capitalize else expire_data_after_sign_in! user.resend_confirmation_instructions unless user.confirmed? redirect_to decidim.root_path flash[:notice] = t("devise.registrations.signed_up_but_unconfirmed") end end on(:invalid) do :notice, :success, kind: @form.provider.capitalize render :new end on(:error) do |user| if user.errors[:email] :alert, :failure, kind: @form.provider.capitalize, reason: t("decidim.devise.omniauth_registrations.create.email_already_exists") end render :new end end end |
#first_login_and_not_authorized?(user) ⇒ Boolean
66 67 68 |
# File 'app/controllers/decidim/devise/omniauth_registrations_controller.rb', line 66 def (user) user.is_a?(User) && user.sign_in_count == 1 && Decidim::Verifications.workflows.any? && user.verifiable? end |
#new ⇒ Object
10 11 12 |
# File 'app/controllers/decidim/devise/omniauth_registrations_controller.rb', line 10 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.
62 63 64 |
# File 'app/controllers/decidim/devise/omniauth_registrations_controller.rb', line 62 def pending_redirect?(user) store_location_for(user, stored_location_for(user)) end |