Sha256: 0b15d94de4cab938627a71b3ee0cb6958ceff2a3f20edc952e7c07736eec96be

Contents?: true

Size: 1.47 KB

Versions: 9

Compression:

Stored size: 1.47 KB

Contents

# frozen_string_literal: true

module Decidim
  module Devise
    # Custom Devise SessionsController to avoid namespace problems.
    class SessionsController < ::Devise::SessionsController
      include Decidim::DeviseControllers

      before_action :check_sign_in_enabled, only: :create

      def create
        super
      end

      def destroy
        current_user.invalidate_all_sessions!
        super
      end

      def after_sign_in_path_for(user)
        if first_login_and_not_authorized?(user) && !user.admin? && !pending_redirect?(user)
          decidim_verifications.first_login_authorizations_path
        else
          super
        end
      end

      # 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.
      def pending_redirect?(user)
        store_location_for(user, stored_location_for(user))
      end

      def first_login_and_not_authorized?(user)
        user.is_a?(User) && user.sign_in_count == 1 && current_organization.available_authorizations.any? && user.verifiable?
      end

      def after_sign_out_path_for(user)
        request.referer || super
      end

      private

      def check_sign_in_enabled
        redirect_to new_user_session_path unless current_organization.sign_in_enabled?
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
decidim-core-0.23.6 app/controllers/decidim/devise/sessions_controller.rb
decidim-core-0.23.5 app/controllers/decidim/devise/sessions_controller.rb
decidim-core-0.23.4 app/controllers/decidim/devise/sessions_controller.rb
decidim-core-0.23.3 app/controllers/decidim/devise/sessions_controller.rb
decidim-core-0.23.2 app/controllers/decidim/devise/sessions_controller.rb
decidim-core-0.23.1 app/controllers/decidim/devise/sessions_controller.rb
decidim-core-0.23.1.rc1 app/controllers/decidim/devise/sessions_controller.rb
decidim-core-0.23.0 app/controllers/decidim/devise/sessions_controller.rb
decidim-core-0.22.0 app/controllers/decidim/devise/sessions_controller.rb