0001-password-field-can-disable-confirmation-input-8111.patch
tests/test_widgets.py | ||
---|---|---|
146 | 146 |
mock_form_submission(req, widget, {'test$pwd1': 'foo', 'test$pwd2': 'foo'}) |
147 | 147 |
assert widget.parse() == {'cleartext': 'foo'} |
148 | 148 | |
149 |
widget = PasswordEntryWidget('test', formats=['cleartext'], confirmation=False) |
|
150 |
req.form = {} |
|
151 |
mock_form_submission(req, widget, {'test$pwd1': 'foo'}) |
|
152 |
assert widget.parse() == {'cleartext': 'foo'} |
|
153 | ||
149 | 154 | |
150 | 155 |
def test_passwordentry_widget_errors(): |
151 | 156 |
# mismatch |
wcs/fields.py | ||
---|---|---|
1655 | 1655 |
count_lowercase = 0 |
1656 | 1656 |
count_digit = 0 |
1657 | 1657 |
count_special = 0 |
1658 |
confirmation = True |
|
1658 | 1659 |
confirmation_title = None |
1659 | 1660 |
formats = ['sha1'] |
1660 | 1661 |
extra_attributes = ['formats', 'min_length', 'max_length', |
1661 | 1662 |
'count_uppercase', 'count_lowercase', 'count_digit', |
1662 |
'count_special', 'confirmation_title'] |
|
1663 |
'count_special', 'confirmation', 'confirmation_title']
|
|
1663 | 1664 | |
1664 | 1665 |
widget_class = PasswordEntryWidget |
1665 | 1666 | |
... | ... | |
1691 | 1692 |
form.add(IntWidget, 'count_special', |
1692 | 1693 |
title=_('Minimum number of special characters'), |
1693 | 1694 |
value=self.count_special) |
1695 |
form.add(CheckboxWidget, 'confirmation', |
|
1696 |
title=_('Add a confirmation input'), |
|
1697 |
value=self.confirmation) |
|
1694 | 1698 |
form.add(StringWidget, 'confirmation_title', size=50, |
1695 | 1699 |
title=_('Label for confirmation input'), |
1696 | 1700 |
value=self.confirmation_title) |
wcs/qommon/form.py | ||
---|---|---|
1842 | 1842 |
count_lowercase = 0 |
1843 | 1843 |
count_digit = 0 |
1844 | 1844 |
count_special = 0 |
1845 |
confirmation = True |
|
1845 | 1846 | |
1846 | 1847 |
def __init__(self, name, value=None, **kwargs): |
1847 | 1848 |
# hint will be displayed with pwd1 widget |
... | ... | |
1853 | 1854 |
self.count_lowercase = kwargs.get('count_lowercase', 0) |
1854 | 1855 |
self.count_digit = kwargs.get('count_digit', 0) |
1855 | 1856 |
self.count_special = kwargs.get('count_special', 0) |
1857 |
self.confirmation = kwargs.get('confirmation', True) |
|
1856 | 1858 |
confirmation_title = kwargs.get('confirmation_title') or _('Confirmation') |
1857 | 1859 | |
1858 | 1860 |
self.formats = kwargs.get('formats', ['sha1']) |
... | ... | |
1862 | 1864 |
required=kwargs.get('required', False), |
1863 | 1865 |
autocomplete='off', |
1864 | 1866 |
hint=hint) |
1865 |
self.add(PasswordWidget, name='pwd2', title=confirmation_title, |
|
1866 |
required=kwargs.get('required', False), |
|
1867 |
autocomplete='off') |
|
1867 |
if self.confirmation: |
|
1868 |
self.add(PasswordWidget, name='pwd2', title=confirmation_title, |
|
1869 |
required=kwargs.get('required', False), |
|
1870 |
autocomplete='off') |
|
1868 | 1871 |
else: |
1869 | 1872 |
encoded_value = base64.encodestring(json.dumps(value)) |
1870 | 1873 |
if value: |
... | ... | |
1912 | 1915 |
request.form.get('%s$encoded' % self.name))) |
1913 | 1916 |
return |
1914 | 1917 |
pwd1 = self.get('pwd1') or '' |
1915 |
pwd2 = self.get('pwd2') or '' |
|
1916 | 1918 | |
1917 | 1919 |
if not self.get_widget('pwd1'): |
1918 | 1920 |
# we are in read-only mode, stop here. |
... | ... | |
1955 | 1957 |
'Password must contain at least %(count)d special characters.', |
1956 | 1958 |
count) % {'count': count}) |
1957 | 1959 | |
1958 |
if pwd1 != pwd2: |
|
1959 |
self.get_widget('pwd2').set_error(_('Passwords do not match')) |
|
1960 |
pwd1 = None |
|
1960 |
if self.confirmation: |
|
1961 |
pwd2 = self.get('pwd2') or '' |
|
1962 |
if pwd1 != pwd2: |
|
1963 |
self.get_widget('pwd2').set_error(_('Passwords do not match')) |
|
1964 |
pwd1 = None |
|
1965 | ||
1961 | 1966 |
if set_errors: |
1962 | 1967 |
self.get_widget('pwd1').set_error(' '.join(set_errors)) |
1963 | 1968 |
pwd1 = None |
1964 |
- |