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
66 67 68 69 |
# File 'app/controllers/decidim/devise/omniauth_registrations_controller.rb', line 66 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
46 47 48 49 50 51 52 |
# File 'app/controllers/decidim/devise/omniauth_registrations_controller.rb', line 46 def after_sign_in_path_for(user) if !pending_redirect?(user) && (user) 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 |
# 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! 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 |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
62 63 64 |
# File 'app/controllers/decidim/devise/omniauth_registrations_controller.rb', line 62 def (user) user.is_a?(User) && user.sign_in_count == 1 && Decidim..any? 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.
58 59 60 |
# File 'app/controllers/decidim/devise/omniauth_registrations_controller.rb', line 58 def pending_redirect?(user) store_location_for(user, stored_location_for(user)) end |