Class: Decidim::Devise::OmniauthRegistrationsController
- Inherits:
-
Devise::OmniauthCallbacksController
- Object
- Devise::OmniauthCallbacksController
- Decidim::Devise::OmniauthRegistrationsController
- 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
- #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
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 after_sign_in_path_for(user) if !pending_redirect?(user) && (user) else super end end |
#create ⇒ Object
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? sign_in_and_redirect user, event: :authentication :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 :notice, :success, kind: @form.provider.capitalize render :new end on(:error) do redirect_to decidim.new_user_registration_path :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
63 64 65 |
# File 'app/controllers/decidim/devise/omniauth_registrations_controller.rb', line 63 def (user) user.is_a?(User) && user.sign_in_count == 1 && Decidim..any? end |
#new ⇒ Object
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.
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 |