Sha256: 57db0bac53911c8f77cb4576ef15893c1bd511d54d85d9d12630655aa222d389

Contents?: true

Size: 1.2 KB

Versions: 4

Compression:

Stored size: 1.2 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?
          decidim.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

4 entries across 4 versions & 1 rubygems

Version Path
decidim-core-0.29.2 app/controllers/concerns/decidim/devise_authentication_methods.rb
decidim-core-0.28.5 app/controllers/concerns/decidim/devise_authentication_methods.rb
decidim-core-0.29.1 app/controllers/concerns/decidim/devise_authentication_methods.rb
decidim-core-0.28.4 app/controllers/concerns/decidim/devise_authentication_methods.rb