From ed228c4bd7a5e15a6fc65eb95bc067e3fd8f076d Mon Sep 17 00:00:00 2001 From: Julius Date: Sun, 22 Dec 2013 23:21:14 +0100 Subject: [PATCH] Allow control of password autocomplete by flag --- app/helpers/application_helper.rb | 10 ++++++++++ app/views/home/profile.html.haml | 2 +- app/views/shared/_user_form_fields.html.haml | 9 +++++---- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ef516a67..fab0bde0 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -203,5 +203,15 @@ module ApplicationHelper :title => I18n.t('helpers.application.write_message') 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 diff --git a/app/views/home/profile.html.haml b/app/views/home/profile.html.haml index 0b164d73..31fa9ee9 100644 --- a/app/views/home/profile.html.haml +++ b/app/views/home/profile.html.haml @@ -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 diff --git a/app/views/shared/_user_form_fields.html.haml b/app/views/shared/_user_form_fields.html.haml index bf0af9bc..a0afffd6 100644 --- a/app/views/shared/_user_form_fields.html.haml +++ b/app/views/shared/_user_form_fields.html.haml @@ -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|