Allow forms to disable autofill in all browsers

New variable added to form to specify whether it should autofill or
not. This updates the modal forms autocomplete attribute. Hidden
fields are required because Chromium v34+ based browsers ignore the
autocomplete=off form attribute, so the hidden fields catch autofill
data. Any form without self.no_autocomplete = True will just act
like before.

Change-Id: Ibb1722023eea8f57312e1133939d1f75cd909467
Closes-Bug: 1352459
This commit is contained in:
Sam Betts 2014-08-14 19:01:22 +01:00
parent 035b9868c3
commit e79af0ac1e
2 changed files with 10 additions and 1 deletions

View File

@ -14,12 +14,19 @@
<form id="{% block form_id %}{% endblock %}"
ng-controller="{% block ng_controller %}DummyCtrl{% endblock %}"
name="{% block form_name %}{% endblock %}"
autocomplete="{% block autocomplete %}{% endblock %}"
autocomplete="{% block autocomplete %}{% if form.no_autocomplete %}off{% endif %}{% endblock %}"
class="{% block form_class %}{% endblock %}"
action="{% block form_action %}{% endblock %}"
method="{% block form-method %}POST{% endblock %}"
{% if add_to_field %}data-add-to-field="{{ add_to_field }}"{% endif %} {% block form_attrs %}{% endblock %}>{% csrf_token %}
<div class="modal-body clearfix">
{% comment %}
These fake fields are required to prevent Chrome v34+ from autofilling form.
{% endcomment %}
{% if form.no_autocomplete %}
<input type="text" name="fake_email" value="" style="display: none" />
<input type="password" name="fake_password" value="" style="display: none" />
{% endif %}
{% block modal-body %}
<fieldset>
{% include "horizon/common/_form_fields.html" %}

View File

@ -95,6 +95,7 @@ class CreateUserForm(BaseUserForm):
add_item_link=ADD_PROJECT_URL)
role_id = forms.ChoiceField(label=_("Role"),
required=PROJECT_REQUIRED)
no_autocomplete = True
def __init__(self, *args, **kwargs):
roles = kwargs.pop('roles')
@ -173,6 +174,7 @@ class UpdateUserForm(BaseUserForm):
required=False)
project = forms.ChoiceField(label=_("Primary Project"),
required=PROJECT_REQUIRED)
no_autocomplete = True
def __init__(self, request, *args, **kwargs):
super(UpdateUserForm, self).__init__(request, *args, **kwargs)