Module: Decidim::PasswordsHelper

Defined in:
app/helpers/decidim/passwords_helper.rb

Instance Method Summary collapse

Instance Method Details

#needs_admin_password?(user) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
# File 'app/helpers/decidim/passwords_helper.rb', line 34

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

  true
end

#password_field_options_for(user) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/helpers/decidim/passwords_helper.rb', line 5

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