Sha256: 25286c34c282aea975b3f13bebba6e100ac3a765cbacdbf4c93080a71fc80adf

Contents?: true

Size: 1.03 KB

Versions: 12

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module Decidim
  module PasswordsHelper
    def password_field_options_for(user)
      user =
        case user
        when :user
          Decidim::User.new
        when :admin
          Decidim::User.new(admin: true)
        when String
          Decidim::User.with_reset_password_token(user)
        else
          user
        end
      min_length = ::PasswordValidator.minimum_length_for(user)
      help_text =
        if needs_admin_password?(user)
          t("devise.passwords.edit.password_help_admin", minimun_characters: min_length)
        else
          t("devise.passwords.edit.password_help", minimun_characters: min_length)
        end

      {
        autocomplete: "new-password",
        required: true,
        help_text: help_text,
        minlength: min_length,
        maxlength: ::PasswordValidator::MAX_LENGTH
      }
    end

    def needs_admin_password?(user)
      return false unless user&.admin?
      return false unless Decidim.config.admin_password_strong

      true
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-core-0.27.9 app/helpers/decidim/passwords_helper.rb
decidim-core-0.27.8 app/helpers/decidim/passwords_helper.rb
decidim-core-0.27.7 app/helpers/decidim/passwords_helper.rb
decidim-core-0.27.6 app/helpers/decidim/passwords_helper.rb
decidim-core-0.27.5 app/helpers/decidim/passwords_helper.rb
decidim-core-0.27.4 app/helpers/decidim/passwords_helper.rb
decidim-core-0.27.3 app/helpers/decidim/passwords_helper.rb
decidim-core-0.27.2 app/helpers/decidim/passwords_helper.rb
decidim-core-0.27.1 app/helpers/decidim/passwords_helper.rb
decidim-core-0.27.0 app/helpers/decidim/passwords_helper.rb
decidim-core-0.27.0.rc2 app/helpers/decidim/passwords_helper.rb
decidim-core-0.27.0.rc1 app/helpers/decidim/passwords_helper.rb