Sha256: d4d6e5577177ace579e3f52f8498f8804cfa7e6df2a2bee3cb42bb9f3c4d8988

Contents?: true

Size: 1.39 KB

Versions: 13

Compression:

Stored size: 1.39 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", minimum_characters: min_length)
        else
          t("devise.passwords.edit.password_help", minimum_characters: min_length)
        end

      {
        autocomplete: "new-password",
        required: true,
        label: false,
        help_text:,
        value: @account&.password,
        minlength: min_length,
        maxlength: ::PasswordValidator::MAX_LENGTH,
        placeholder: "••••••"
      }
    end

    def old_password_options
      help_text = t("devise.passwords.edit.old_password_help").html_safe

      {
        autocomplete: "current-password",
        required: true,
        label: false,
        help_text:,
        placeholder: "••••••"
      }
    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

13 entries across 13 versions & 1 rubygems

Version Path
decidim-core-0.29.1 app/helpers/decidim/passwords_helper.rb
decidim-core-0.28.4 app/helpers/decidim/passwords_helper.rb
decidim-core-0.29.0 app/helpers/decidim/passwords_helper.rb
decidim-core-0.28.3 app/helpers/decidim/passwords_helper.rb
decidim-core-0.29.0.rc4 app/helpers/decidim/passwords_helper.rb
decidim-core-0.29.0.rc3 app/helpers/decidim/passwords_helper.rb
decidim-core-0.29.0.rc2 app/helpers/decidim/passwords_helper.rb
decidim-core-0.29.0.rc1 app/helpers/decidim/passwords_helper.rb
decidim-core-0.28.2 app/helpers/decidim/passwords_helper.rb
decidim-core-0.28.1 app/helpers/decidim/passwords_helper.rb
decidim-core-0.28.0 app/helpers/decidim/passwords_helper.rb
decidim-core-0.28.0.rc5 app/helpers/decidim/passwords_helper.rb
decidim-core-0.28.0.rc4 app/helpers/decidim/passwords_helper.rb