changeset 138:81654a482b3a

Added createonly parameter to UserPreferences macro and userform action; moved mailAccountData to the user object; extended SystemAdmin to offer 'send acount data' links; fixed minor quoting problem in Page.link_to() imported from: moin--main--1.5--patch-140
author Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
date Tue, 25 Oct 2005 16:31:32 +0000
parents cfbecd3400d3
children 639dc94d4c52
files MoinMoin/Page.py MoinMoin/user.py MoinMoin/userform.py MoinMoin/wikimacro.py
diffstat 4 files changed, 79 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/Page.py	Sun Oct 23 20:36:07 2005 +0000
+++ b/MoinMoin/Page.py	Tue Oct 25 16:31:32 2005 +0000
@@ -835,9 +835,11 @@
         # Create url, excluding scriptname
         url = wikiutil.quoteWikinameURL(self.page_name)
         if querystr:
+            if not isinstance(querystr, type({})):
+                # makeQueryString does not escape strings any more
+                querystr = wikiutil.escape(querystr)
+                
             querystr = wikiutil.makeQueryString(querystr)
-            # makeQueryString does not escape any more
-            querystr = wikiutil.escape(querystr)
             url = "%s?%s" % (url, querystr)
 
         # Add anchor
--- a/MoinMoin/user.py	Sun Oct 23 20:36:07 2005 +0000
+++ b/MoinMoin/user.py	Tue Oct 25 16:31:32 2005 +0000
@@ -908,3 +908,33 @@
             markup = '%s:%s' % (wikiname, pagename.replace(" ","_")) 
         return markup
 
+    def mailAccountData(self, cleartext_passwd=None):
+        from MoinMoin.util import mail
+        _ = self._request.getText
+
+        text = '\n' + _("""\
+Login Name: %s
+
+Login Password: %s
+
+Login URL: %s/?action=userform&uid=%s
+""", formatted=False) % (
+                        self.name, self.enc_password, self._request.getBaseURL(), self.id)
+
+        text = _("""\
+Somebody has requested to submit your account data to this email address.
+
+If you lost your password, please use the data below and just enter the
+password AS SHOWN into the wiki's password form field (use copy and paste
+for that).
+
+After successfully logging in, it is of course a good idea to set a new and known password.
+""", formatted=False) + text
+
+
+        subject = _('[%(sitename)s] Your wiki account data',
+                    formatted=False) % {'sitename': self._cfg.sitename or "Wiki"}
+        mailok, msg = mail.sendmail(self._request, [self.email], subject,
+                                    text, mail_from=self._cfg.mail_from)
+        return msg
+        
--- a/MoinMoin/userform.py	Sun Oct 23 20:36:07 2005 +0000
+++ b/MoinMoin/userform.py	Tue Oct 25 16:31:32 2005 +0000
@@ -80,38 +80,16 @@
             except KeyError:
                 return _("Please provide a valid email address!")
     
-            text = ''
             users = user.getUserList(self.request)
             for uid in users:
                 theuser = user.User(self.request, uid)
                 if theuser.valid and theuser.email.lower() == email:
-                    text += '\n' + _("""\
-Login Name: %s
-
-Login Password: %s
-
-Login URL: %s/?action=userform&uid=%s
-""", formatted=False) % (
-                        theuser.name, theuser.enc_password, self.request.getBaseURL(), theuser.id)
-
-            if not text:
-                return _("Found no account matching the given email address '%(email)s'!") % {'email': wikiutil.escape(email)}
+                    msg = theuser.mailAccountData()
+                    return wikiutil.escape(msg)
 
-            text = _("""\
-Somebody has requested to submit your account data to this email address.
-
-If you lost your password, please use the data below and just enter the
-password AS SHOWN into the wiki's password form field (use copy and paste
-for that).
+            return _("Found no account matching the given email address '%(email)s'!") % {'email': wikiutil.escape(email)}
 
-After successfully logging in, it is of course a good idea to set a new and known password.
-""", formatted=False) + text
 
-            subject = _('[%(sitename)s] Your wiki account data',
-                formatted=False) % {'sitename': self.cfg.sitename or "Wiki"}
-            mailok, msg = util.mail.sendmail(self.request, [email], subject,
-                text, mail_from=self.cfg.mail_from)
-            return wikiutil.escape(msg)
 
         if form.has_key('login'):
             # Trying to login with a user name and a password
@@ -159,9 +137,14 @@
             self.request.setCookie()           
         
         
-        elif form.has_key('create'):
+        elif (form.has_key('create') or
+              form.has_key('create_only') or
+              form.has_key('create_and_mail')):
             # Create user profile
-            theuser = self.request.get_user()
+            if form.has_key('create'):
+                theuser = self.request.get_user()
+            else:
+                theuser = user.User(self.request)
                 
             # Require non-empty name
             try:
@@ -221,10 +204,14 @@
                         return _("This email already belongs to somebody else.")
 
             # save data and send cookie
-            theuser.save()            
-            self.request.user = theuser
-            self.request.setCookie()
+            theuser.save()
+            if form.has_key('create'):
+                self.request.user = theuser
+                self.request.setCookie()
 
+            if form.has_key('create_and_mail'):
+                theuser.mailAccountData()
+            
             result = _("User account created!")
             if _debug:
                 result = result + util.dumpFormData(form)
@@ -492,12 +479,12 @@
         ]))
 
 
-    def asHTML(self):
+    def asHTML(self, create_only=False):
         """ Create the complete HTML form code. """
         _ = self._
         self.make_form()
 
-        if self.request.user.valid:
+        if self.request.user.valid and not create_only:
             buttons = [
                 ('save', _('Save')),
                 ('logout', _('Logout')),
@@ -592,11 +579,19 @@
             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=getattr(self.request.user, key)), ' ', _(textafter), ])
+                              [ html.INPUT(type=type, size=length, name=key,
+                                           value=''),
+                                ' ', _(textafter), ])
 
         if self.cfg.mail_enabled:
             buttons.append(("account_sendmail", _('Mail me my account data')))
 
+        if create_only:
+            buttons = [("create_only", _('Create Profile'))]
+            if self.cfg.mail_enabled:
+                buttons.append(("create_and_mail", "%s + %s" %
+                                (_('Create Profile'), _('Email'))))
+
         # Add buttons
         button_cell = []
         for name, label in buttons:
@@ -610,9 +605,9 @@
         return unicode(self._form)
 
 
-def getUserForm(request):
+def getUserForm(request, create_only=False):
     """ Return HTML code for the user settings. """
-    return UserSettings(request).asHTML()
+    return UserSettings(request).asHTML(create_only=create_only)
 
 
 #############################################################################
@@ -630,7 +625,7 @@
         #Column('id', label=('ID'), align='right'),
         Column('name', label=('Username')),
         Column('email', label=('Email')),
-        #Column('action', label=_('Action')),
+        Column('action', label=_('Action')),
     ]
 
     # Iterate over users
@@ -649,7 +644,11 @@
             (request.formatter.url(1, 'mailto:' + account.email, css='mailto', unescaped=1) +
              request.formatter.text(account.email) +
              request.formatter.url(0)),
-            #'',
+            request.page.link_to(request, text=_('Mail me my account data'),
+                                 querystr= {"action":"userform",
+                                            "email": account.email,  
+                                            "account_sendmail": "1",
+                                            "sysadm": "users",})
         ))
 
     if data:
--- a/MoinMoin/wikimacro.py	Sun Oct 23 20:36:07 2005 +0000
+++ b/MoinMoin/wikimacro.py	Tue Oct 25 16:31:32 2005 +0000
@@ -537,7 +537,15 @@
 
     def _macro_UserPreferences(self, args):
         from MoinMoin import userform
-        return self.formatter.rawHTML(userform.getUserForm(self.request))
+
+        create_only = False
+        if isinstance(args, unicode):
+            args = args.strip(" '\"")
+            create_only = (args.lower()=="createonly")
+
+        return self.formatter.rawHTML(userform.getUserForm(
+            self.request,
+            create_only=create_only))
 
     def _macro_Anchor(self, args):
         return self.formatter.anchordef(args or "anchor")