changeset 2366:2f36b737022a

split recoverpass form from prefs
author Johannes Berg <johannes AT sipsolutions DOT net>
date Thu, 12 Jul 2007 11:40:20 +0200
parents b9feee61d28e
children 405032c82324
files MoinMoin/action/recoverpass.py MoinMoin/userprefs/prefs.py
diffstat 2 files changed, 31 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/recoverpass.py	Thu Jul 12 11:40:04 2007 +0200
+++ b/MoinMoin/action/recoverpass.py	Thu Jul 12 11:40:20 2007 +0200
@@ -9,7 +9,6 @@
 from MoinMoin import user, wikiutil
 from MoinMoin.Page import Page
 from MoinMoin.widget import html
-from MoinMoin.userprefs.prefs import Settings
 
 def _do_recover(request):
     _ = request.getText
@@ -29,6 +28,33 @@
 
     return _("Found no account matching the given email address '%(email)s'!") % {'email': email}
 
+def _create_form(request):
+    _ = request.getText
+    url = request.page.url(request)
+    ret = html.FORM(action=url)
+    ret.append(html.INPUT(type='hidden', name='action', value='recoverpass'))
+    lang_attr = request.theme.ui_lang_attr()
+    ret.append(html.Raw('<div class="userpref"%s>' % lang_attr))
+    tbl = html.TABLE(border="0")
+    ret.append(tbl)
+    ret.append(html.Raw('</div>'))
+
+    row = html.TR()
+    tbl.append(row)
+    row.append(html.TD().append(html.STRONG().append(html.Text(_("Email")))))
+    row.append(html.TD().append(html.INPUT(type="text", size="36",
+                                           name="email")))
+
+    row = html.TR()
+    tbl.append(row)
+    row.append(html.TD())
+    td = html.TD()
+    row.append(td)
+    td.append(html.INPUT(type="submit", name="account_sendmail",
+                         value=_('Mail me my account data')))
+
+    return unicode(ret)
+
 
 def execute(pagename, request):
     pagename = pagename
@@ -51,8 +77,7 @@
             request.write(_("""This wiki is not enabled for mail processing.
 Contact the owner of the wiki, who can enable email."""))
         else:
-            # THIS IS A BIG HACK. IT NEEDS TO BE CLEANED UP
-            request.write(Settings(request).create_form(recover_only=True))
+            request.write(_create_form(request))
 
             request.write(_("""
 == Recovering a lost password ==
--- a/MoinMoin/userprefs/prefs.py	Thu Jul 12 11:40:04 2007 +0200
+++ b/MoinMoin/userprefs/prefs.py	Thu Jul 12 11:40:20 2007 +0200
@@ -16,13 +16,8 @@
 #################################################################
 # This is a mess.
 #
-# This plugin is also used by the 'newaccount'
-# action and really shouldn't be.
-#
 # The plan for refactoring would be:
-#  1. make the 'newaccount' action create its own form and not
-#     use the code here
-#  2. split the plugin into multiple preferences pages:
+# split the plugin into multiple preferences pages:
 #    - account details (name, email, timezone, ...)
 #    - change password
 #    - wiki settings (editor, fancy diffs, theme, ...)
@@ -376,12 +371,12 @@
         ]))
 
 
-    def create_form(self, recover_only=False):
+    def create_form(self):
         """ Create the complete HTML form code. """
         _ = self._
         self._make_form()
 
-        if self.request.user.valid and not recover_only:
+        if self.request.user.valid:
             buttons = [('save', _('Save')), ('cancel', _('Cancel')), ]
             uf_remove = self.cfg.user_form_remove
             uf_disable = self.cfg.user_form_disable
@@ -476,34 +471,6 @@
                 )
             self._form.append(html.INPUT(type="hidden", name="action", value="userprefs"))
             self._form.append(html.INPUT(type="hidden", name="handler", value="prefs"))
-        elif not recover_only:
-            # Login / register interface
-            buttons = [
-                # IMPORTANT: login should be first to be the default
-                # button when a user hits ENTER.
-                #('login', _('Login')),  # we now have a Login macro
-                ('create', _('Create Profile')),
-                ('cancel', _('Cancel')),
-            ]
-            for key, label, type, length, textafter in self.cfg.user_form_fields:
-                if key in ('name', 'password', 'password2', 'email'):
-                    self.make_row(_(label),
-                              [html.INPUT(type=type, size=length, name=key,
-                                          value=''),
-                               ' ', _(textafter), ])
-            self._form.append(html.INPUT(type="hidden", name="action", value="newaccount"))
-        else:
-            for key, label, type, length, textafter in self.cfg.user_form_fields:
-                if key == 'email':
-                    self.make_row(_(label),
-                              [html.INPUT(type=type, size=length, name=key,
-                                          value=''),
-                               ' ', _(textafter), ])
-            buttons = []
-            self._form.append(html.INPUT(type="hidden", name="action", value="recoverpass"))
-
-        if recover_only and self.cfg.mail_enabled:
-            buttons.append(("account_sendmail", _('Mail me my account data')))
 
         # Add buttons
         button_cell = []