Allow control of password autocomplete by flag

This commit is contained in:
Julius 2013-12-22 23:21:14 +01:00
parent 53e611c1c0
commit ed228c4bd7
3 changed files with 16 additions and 5 deletions

View file

@ -204,4 +204,14 @@ module ApplicationHelper
end
end
# provide input_html for password autocompletion
def autocomplete_flag_to_password_html(password_autocomplete)
case password_autocomplete
when true then {autocomplete: 'on'}
when false then {autocomplete: 'off'}
when 'store-only' then {autocomplete: 'off', data: {store: 'on'}}
else {}
end
end
end

View file

@ -6,7 +6,7 @@
= h(t('.user.title', user: show_user))
%small= t '.user.since', when: distance_of_time_in_words(Time.now, @current_user.created_on)
= simple_form_for(@current_user, :url => update_profile_path) do |f|
= render :partial => 'shared/user_form_fields', :locals => {:f => f, :password_autocomplete => false}
= render :partial => 'shared/user_form_fields', :locals => {:f => f, :password_autocomplete => 'store-only'}
.form-actions
= submit_tag t('ui.save'), class: 'btn'
.span5

View file

@ -3,12 +3,13 @@
= f.input :email
-# need :required because :use_nil option on user model validators break the required mark
= f.input :nick, required: true if FoodsoftConfig[:use_nick]
-# you can disable password autocompletion by passing `password_autocomplete: false` to this partial
-# You can control password autocompletion by passing `password_autocomplete` to this partial.
-# Possible values: undefined/nil, true, false, 'store-only'
-# see also https://github.com/foodcoops/foodsoft/wiki/Form-autocompletion
- password_autocomplete = nil unless defined?(:password_autocomplete)
- passwd_opts = (password_autocomplete.nil? ? {} : {autocomplete: password_autocomplete ? 'on' : 'off', data: {store: 'on'}})
= f.input :password, :required => f.object.new_record?, input_html: passwd_opts
= f.input :password_confirmation, :required => f.object.new_record?, input_html: passwd_opts
- password_html = autocomplete_flag_to_password_html(password_autocomplete)
= f.input :password, :required => f.object.new_record?, input_html: password_html
= f.input :password_confirmation, :required => f.object.new_record?, input_html: password_html
= f.input :phone
= f.simple_fields_for :settings_attributes do |s|