Sha256: c84de53f75fd8d809d7bb4b26a12e6935e65d969557b898a40be5e66d30945ee

Contents?: true

Size: 1.46 KB

Versions: 25

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

module Decidim
  # Force user to "Change your password" view when they need to change password
  module NeedsPasswordChange
    extend ActiveSupport::Concern

    included do
      before_action :check_password_update_required
    end

    private

    def check_password_update_required
      return unless request.format.html?
      return unless current_user
      return unless current_user.admin?
      return unless Decidim.config.admin_password_strong
      return unless current_user.needs_password_update?
      return if password_update_permitted_path?(request.path)

      redirect_to_change_password
    end

    def password_update_permitted_path?(target_path)
      permitted_paths = [(tos_path if respond_to?(:tos_path, true)),
                         decidim.delete_account_path,
                         decidim.accept_tos_path,
                         decidim.download_your_data_path,
                         decidim.export_download_your_data_path,
                         decidim.download_file_download_your_data_path,
                         decidim.change_password_path].compact
      # ensure that path with or without query string pass
      permitted_paths.find { |el| el.split("?").first == target_path }
    end

    def redirect_to_change_password
      flash[:notice] = flash[:notice] if flash[:notice]
      flash[:secondary] = t("decidim.admin.password_change.alert")
      redirect_to decidim.change_password_path
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
decidim-core-0.29.1 app/controllers/concerns/decidim/needs_password_change.rb
decidim-core-0.28.4 app/controllers/concerns/decidim/needs_password_change.rb
decidim-core-0.27.9 app/controllers/concerns/decidim/needs_password_change.rb
decidim-core-0.29.0 app/controllers/concerns/decidim/needs_password_change.rb
decidim-core-0.28.3 app/controllers/concerns/decidim/needs_password_change.rb
decidim-core-0.27.8 app/controllers/concerns/decidim/needs_password_change.rb
decidim-core-0.29.0.rc4 app/controllers/concerns/decidim/needs_password_change.rb
decidim-core-0.29.0.rc3 app/controllers/concerns/decidim/needs_password_change.rb
decidim-core-0.29.0.rc2 app/controllers/concerns/decidim/needs_password_change.rb
decidim-core-0.29.0.rc1 app/controllers/concerns/decidim/needs_password_change.rb
decidim-core-0.28.2 app/controllers/concerns/decidim/needs_password_change.rb
decidim-core-0.27.7 app/controllers/concerns/decidim/needs_password_change.rb
decidim-core-0.28.1 app/controllers/concerns/decidim/needs_password_change.rb
decidim-core-0.27.6 app/controllers/concerns/decidim/needs_password_change.rb
decidim-core-0.28.0 app/controllers/concerns/decidim/needs_password_change.rb
decidim-core-0.27.5 app/controllers/concerns/decidim/needs_password_change.rb
decidim-core-0.28.0.rc5 app/controllers/concerns/decidim/needs_password_change.rb
decidim-core-0.28.0.rc4 app/controllers/concerns/decidim/needs_password_change.rb
decidim-core-0.27.4 app/controllers/concerns/decidim/needs_password_change.rb
decidim-core-0.27.3 app/controllers/concerns/decidim/needs_password_change.rb