Merge lp:~forrest-aldridge/methanal/verified-password-input into lp:methanal

Proposed by Forrest Aldridge
Status: Rejected
Rejected by: Tristan Seligmann
Proposed branch: lp:~forrest-aldridge/methanal/verified-password-input
Merge into: lp:methanal
Diff against target: 136 lines
4 files modified
methanal/js/Methanal/Tests/TestView.js (+43/-0)
methanal/js/Methanal/View.js (+35/-0)
methanal/themes/methanal-base/methanal-verified-password-input.html (+15/-0)
methanal/view.py (+9/-0)
To merge this branch: bzr merge lp:~forrest-aldridge/methanal/verified-password-input
Reviewer Review Type Date Requested Status
Jonathan Jacobs Approve
Review via email: mp+13130@code.launchpad.net

This proposal supersedes a proposal from 2009-10-08.

To post a comment you must log in.
Revision history for this message
Jonathan Jacobs (jjacobs) wrote : Posted in a previous version of this proposal

  1. Some empty lines have trailing whitespace, please remove this.
  2. Can you align the second line of the 3rd point of "test_inputValidation"'s docstring with the first line?
  3. "test_inputValidation" tests a bunch of different cases, these probably don't need to be split into separate methods but if you could add a comment to indicate which condition is being tested, that would help.
  4. Some lines (excluding subclass lines) are wider than 80 columns.
  5. Please use braces for *ALL* blocks, regardless of the length of their body. "VerifiedPasswordInput.baseValidator" is one specific case I'm looking at.
  6. Replacing the template for things that inherit from "TextInput" makes me twitch, I really don't like this. Unfortunately in this case it doesn't seem to be easily avoidable. The template "methanal-verified-password-input.html" is missing a number of elements that TextInput could be expecting, can you copy "methanal-text-input.html" and modify whatever needs to be?

review: Needs Fixing
Revision history for this message
Jonathan Jacobs (jjacobs) wrote :

This looks good.

I've branched this to add some additional flexibility to the strength checking functionality.

lp:~jjacobs/methanal/verified-password-input

review: Approve

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'methanal/js/Methanal/Tests/TestView.js'
2--- methanal/js/Methanal/Tests/TestView.js 2009-10-04 11:18:09 +0000
3+++ methanal/js/Methanal/Tests/TestView.js 2009-10-09 15:30:24 +0000
4@@ -754,6 +754,49 @@
5
6
7 /**
8+ * Tests for L{Methanal.View.VerifiedPasswordInput}.
9+ */
10+Methanal.Tests.TestView.BaseTestTextInput.subclass(Methanal.Tests.TestView, 'TestVerifiedPasswordInput').methods(
11+ function setUp(self) {
12+ self.controlType = Methanal.View.VerifiedPasswordInput;
13+ },
14+
15+
16+ function createControl(self, args) {
17+ var control = Methanal.Tests.TestView.TestVerifiedPasswordInput.upcall(
18+ self, 'createControl', args);
19+ Methanal.Tests.TestView.makeWidgetChildNode(
20+ control, 'input', 'confirmPassword');
21+ return control;
22+ },
23+
24+
25+ /**
26+ * Validation will fail under the following conditions:
27+ * 1. The input and confirmPasswordNode node values don't match.
28+ * 2. If either of the above node values have no length (are blank).
29+ * 3. If the password value is not strong. By default, 'strong' means
30+ * more than 4 characters long.
31+ */
32+ function test_inputValidation(self) {
33+ self.testControl({value: null},
34+ function (control) {
35+ // Test condition 1
36+ control._confirmPasswordNode.value = 'no match';
37+ self.assertInvalidInput(control, 'match');
38+ control._confirmPasswordNode.value = 'match';
39+ self.assertValidInput(control, 'match');
40+ // Test condition 2
41+ control._confirmPasswordNode.value = '';
42+ self.assertInvalidInput(control, '');
43+ // Test condition 3
44+ self.assertInvalidInput(control, '123');
45+ });
46+ });
47+
48+
49+
50+/**
51 * Tests for L{Methanal.View.InputContainer}.
52 */
53 Methanal.Tests.TestView.BaseTestTextInput.subclass(Methanal.Tests.TestView, 'TestFormGroup').methods(
54
55=== modified file 'methanal/js/Methanal/View.js'
56--- methanal/js/Methanal/View.js 2009-10-05 00:15:43 +0000
57+++ methanal/js/Methanal/View.js 2009-10-09 15:30:24 +0000
58@@ -1793,3 +1793,38 @@
59 return 'Percentage values must be between 0% and 100%'
60 }
61 });
62+
63+
64+
65+/**
66+ * Password input with a verification field and strength checking.
67+ */
68+Methanal.View.TextInput.subclass(Methanal.View, 'VerifiedPasswordInput').methods(
69+ function nodeInserted(self) {
70+ self._confirmPasswordNode = self.nodeById('confirmPassword');
71+ Methanal.View.VerifiedPasswordInput.upcall(self, 'nodeInserted');
72+ },
73+
74+
75+ /**
76+ * Override this method to change the definition of a 'strong' password.
77+ */
78+ function passwordIsStrong(self, password) {
79+ return password.length > 4;
80+ },
81+
82+
83+ /**
84+ * This default validator ensures that the password is strong and that
85+ * the password given in both fields have length > 0 and match exactly.
86+ */
87+ function baseValidator(self, value) {
88+ if (value !== self._confirmPasswordNode.value || value === null ||
89+ self._confirmPasswordNode.value === null) {
90+ return 'Passwords do not match.';
91+ }
92+
93+ if (!self.passwordIsStrong(value)) {
94+ return 'Password is too weak.';
95+ }
96+ });
97
98=== added file 'methanal/themes/methanal-base/methanal-verified-password-input.html'
99--- methanal/themes/methanal-base/methanal-verified-password-input.html 1970-01-01 00:00:00 +0000
100+++ methanal/themes/methanal-base/methanal-verified-password-input.html 2009-10-09 15:30:24 +0000
101@@ -0,0 +1,15 @@
102+<div xmlns:nevow="http://nevow.com/ns/nevow/0.1" xmlns:athena="http://divmod.org/ns/athena/0.7" nevow:render="liveElement">
103+ <input class="methanal-input" type="password">
104+ <nevow:attr name="value" nevow:render="value" />
105+ <athena:handler event="onchange" handler="onChange" />
106+ <athena:handler event="onkeyup" handler="onKeyUp" />
107+ <athena:handler event="onblur" handler="onBlur" />
108+ <athena:handler event="onfocus" handler="onFocus" />
109+ </input>
110+ <input class="methanal-input" type="password" id="confirmPassword">
111+ <nevow:attr name="value" nevow:render="value" />
112+ <athena:handler event="onchange" handler="onChange" />
113+ </input>
114+ <span style="display: none;" class="friendly-representation" id="displayValue" />
115+ <span class="methanal-error" id="error" />
116+</div>
117
118=== modified file 'methanal/view.py'
119--- methanal/view.py 2009-10-04 10:17:26 +0000
120+++ methanal/view.py 2009-10-09 15:30:23 +0000
121@@ -511,6 +511,15 @@
122
123
124
125+class VerifiedPasswordInput(TextInput):
126+ """
127+ Password input with verification and strength checking.
128+ """
129+ fragmentName = 'methanal-verified-password-input'
130+ jsClass = u'Methanal.View.VerifiedPasswordInput'
131+
132+
133+
134 class ChoiceInput(FormInput):
135 """
136 Abstract input with multiple options.

Subscribers

People subscribed via source and target branches