Sha256: fce88fe790d62ea3249702078dfcbf7916891b44160c2d7d77c03c8fefacbffe

Contents?: true

Size: 1.19 KB

Versions: 12

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

require "active_support/concern"

module Decidim
  module DeviseAuthenticationMethods
    extend ActiveSupport::Concern
    include Decidim::UserBlockedChecker

    included do
      def after_sign_in_path_for(user)
        if user.present? && user.blocked?
          check_user_block_status(user)
        elsif user.needs_password_update?
          change_password_path
        elsif 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 is 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
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-core-0.27.9 app/controllers/concerns/decidim/devise_authentication_methods.rb
decidim-core-0.29.0 app/controllers/concerns/decidim/devise_authentication_methods.rb
decidim-core-0.28.3 app/controllers/concerns/decidim/devise_authentication_methods.rb
decidim-core-0.27.8 app/controllers/concerns/decidim/devise_authentication_methods.rb
decidim-core-0.29.0.rc4 app/controllers/concerns/decidim/devise_authentication_methods.rb
decidim-core-0.29.0.rc3 app/controllers/concerns/decidim/devise_authentication_methods.rb
decidim-core-0.29.0.rc2 app/controllers/concerns/decidim/devise_authentication_methods.rb
decidim-core-0.29.0.rc1 app/controllers/concerns/decidim/devise_authentication_methods.rb
decidim-core-0.28.2 app/controllers/concerns/decidim/devise_authentication_methods.rb
decidim-core-0.27.7 app/controllers/concerns/decidim/devise_authentication_methods.rb
decidim-core-0.28.1 app/controllers/concerns/decidim/devise_authentication_methods.rb
decidim-core-0.27.6 app/controllers/concerns/decidim/devise_authentication_methods.rb