Merge pull request #1 from foodcoop-rostock/feature-store-new-password

Allow browser to store new password after change
This commit is contained in:
wvengen 2013-12-23 01:54:50 -08:00
commit 0a6e0ab514
4 changed files with 25 additions and 5 deletions

View File

@ -35,6 +35,15 @@ $.fn.extend({
// Load following statements, when DOM is ready
$(function() {
// The autocomplete attribute is used for both autocompletion and storing
// for passwords, it's nice to store it when editing one's own profile,
// but never autocomplete.
// This is only implemented for passwords.
$('input[type="password"][autocomplete="off"][data-store="on"]').each(function() {
$(this).on('change', function() {
$(this).removeAttr('autocomplete');
});
});
// Show/Hide a specific DOM element
$(document).on('click', 'a[data-toggle-this]', function() {

View File

@ -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

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'})
= 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|