web/formwidgets.py
changeset 3388 b8be8fc77c27
parent 3106 226da883d17a
parent 3387 a357d4147eee
child 3451 6b46d73823f5
--- a/web/formwidgets.py	Tue Sep 22 12:11:12 2009 +0200
+++ b/web/formwidgets.py	Tue Sep 22 13:08:42 2009 +0200
@@ -11,7 +11,7 @@
 from warnings import warn
 
 from cubicweb.common import tags, uilib
-from cubicweb.web import stdmsgs, INTERNAL_FIELD_VALUE
+from cubicweb.web import stdmsgs, INTERNAL_FIELD_VALUE, ProcessFormError
 
 
 class FieldWidget(object):
@@ -63,6 +63,10 @@
             attrs['tabindex'] = form.req.next_tabindex()
         return name, values, attrs
 
+    def process_field_data(self, form, field):
+        formkey = form.form_field_name(field)
+        posted = form.req.form
+        return posted.get(formkey)
 
 class Input(FieldWidget):
     """abstract widget class for <input> tag based widgets"""
@@ -114,11 +118,25 @@
                                       **{'class': 'emphasis'})]
         return u'\n'.join(inputs)
 
+    def process_field_data(self, form, field):
+        passwd1 = super(PasswordInput, self).process_field_data(form, field)
+        fieldname = form.form_field_name(field)
+        passwd2 = form.req.form[fieldname+'-confirm']
+        if passwd1 == passwd2:
+            if passwd1 is None:
+                return None
+            return passwd1.encode('utf-8')
+        raise ProcessFormError(form.req._("password and confirmation don't match"))
 
 class PasswordSingleInput(Input):
     """<input type='password'> without a confirmation field"""
     type = 'password'
 
+    def process_field_data(self, form, field):
+        value = super(PasswordSingleInput, self).process_field_data(form, field)
+        if value is not None:
+            return value.encode('utf-8')
+        return value
 
 class FileInput(Input):
     """<input type='file'>"""