Short description

If you do use the moin command it would be fine to have the possibility after a user creation to invite him by an email from that command tool too. Because if it's the first time the user got's an email with his password it could be a nice idea to add some additional note about the wiki itselfs.

In the following patch this could be done with the --comment parameter.

While writing/using this patch sometimes a new created user does get an empty password emailed. One reason could be that by using moin account create no password was entered. So I do think to avoid this kind of trouble moin account create should always create a random password if no password is entered.

The following patch was tested with version 1.5.6.

   1 # HG changeset patch
   2 # User ReimarBauer <R.Bauer@fz-juelich.de>
   3 # Node ID 7937d0ddbc414c30a245d0ad209812b2fe768c40
   4 # Parent  96706051ff4eac5872a1986cbd83e92cccb214c8
   5 sendmail feature added to send an invitation. sendmail does have an optional --comment key to add some text for an invitation. 
   6 create was changed to create always a password if non was submitted.
   7 
   8 diff -r 96706051ff4e -r 7937d0ddbc41 MoinMoin/script/_util.py
   9 --- a/MoinMoin/script/_util.py	Sat Oct 28 19:29:25 2006 +0200
  10 +++ b/MoinMoin/script/_util.py	Fri Nov 03 17:35:08 2006 +0100
  11 @@ -130,6 +130,7 @@ class MoinScript(Script):
  12              
  13  moin ... account check ...
  14  moin ... account create ...
  15 +moin ... account sendmail ...
  16  moin ... account disable ...
  17  
  18  moin ... cli show ...
  19 diff -r 96706051ff4e -r 7937d0ddbc41 MoinMoin/script/account/create.py
  20 --- a/MoinMoin/script/account/create.py	Sat Oct 28 19:29:25 2006 +0200
  21 +++ b/MoinMoin/script/account/create.py	Fri Nov 03 17:35:08 2006 +0100
  22 @@ -43,6 +43,18 @@ class PluginScript(MoinScript):
  23          request = self.request
  24  
  25          from MoinMoin import user, wikiutil
  26 +        if not self.options.password:
  27 +            import time, sha
  28 +            from random import randint
  29 +            import base64
  30 +
  31 +            charset = 'utf-8'
  32 +            pwd = "%s%d" % (str(time.time()), randint(0, 65535))
  33 +            pwd = pwd.encode(charset)
  34 +            pwd = sha.new(pwd).digest()
  35 +            pwd = '{SHA}%s' % base64.encodestring(pwd).rstrip()
  36 +            self.options.password = pwd
  37 +
  38          u = user.User(request, None, self.options.uname, password=self.options.password)
  39          u.email = self.options.email
  40          u.aliasname = self.options.ualiasname or ''
  41 diff -r 96706051ff4e -r 7937d0ddbc41 MoinMoin/script/account/sendmail.py
  42 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
  43 +++ b/MoinMoin/script/account/sendmail.py	Fri Nov 03 17:35:08 2006 +0100
  44 @@ -0,0 +1,88 @@
  45 +# -*- coding: iso-8859-1 -*-
  46 +"""
  47 +    MoinMoin - invite a user by sending the account data 
  48 +
  49 +    @copyright: 2006 by MoinMoin:ReimarBauer
  50 +    @license: GNU GPL, see COPYING for details.
  51 +"""
  52 +from MoinMoin import user, wikiutil
  53 +from MoinMoin.script._util import MoinScript
  54 +from MoinMoin.util import mail
  55 +
  56 +class PluginScript(MoinScript):
  57 +    def __init__(self, argv, def_values):
  58 +        MoinScript.__init__(self, argv, def_values)
  59 +        self.parser.add_option(
  60 +            "--email", metavar="EMAIL", dest="email",
  61 +            help="Set the user's email address to EMAIL."
  62 +        )
  63 +        self.parser.add_option(
  64 +            "--comment", metavar="comment", dest="comment",
  65 +            help="adds a comment to the mailbody."
  66 +        )
  67 +
  68 +    def get_user(self):
  69 +        users = user.getUserList(self.request)
  70 +        for uid in users:
  71 +            theuser = user.User(self.request, uid)
  72 +            if theuser.valid and theuser.email.lower() == self.options.email.lower():
  73 +                return theuser
  74 +
  75 +    def check_user(self):
  76 +        users = user.getUserList(self.request)
  77 +        for uid in users:
  78 +            theuser = user.User(self.request, uid)
  79 +            if theuser.valid and theuser.email.lower() == self.options.email.lower():
  80 +                return True
  81 +        return False
  82 +
  83 +    def mainloop(self):
  84 +        # we don't expect non-option arguments
  85 +        if len(self.args) != 0:
  86 +            self.parser.error("incorrect number of arguments")
  87 +
  88 +        flags_given = self.options.email
  89 +        if not flags_given:
  90 +            self.parser.print_help()
  91 +            import sys
  92 +            sys.exit(1)
  93 +
  94 +        self.init_request()
  95 +        request = self.request
  96 +        cfg = request.cfg
  97 +
  98 +        if self.check_user():
  99 +            theuser = self.get_user()
 100 +            if len(theuser.enc_password) == 0:
 101 +                print "- Can't invite check the passowrd of this user %s" % (theuser.name)
 102 +                return
 103 +
 104 +            subject = ('[%(sitename)s] Your wiki account data') % {'sitename': self.options.wiki_url or "Wiki"}
 105 +            text = 'Welcome to the Wiki'
 106 +
 107 +            text = '\n' + """\
 108 +Login Name: %s
 109 +
 110 +Login Password: %s
 111 +
 112 +Login URL: %s/?action=login
 113 + """ % (theuser.name, theuser.enc_password, self.options.wiki_url)
 114 +
 115 +            text = """\
 116 +Please use the data below and just enter the
 117 +password AS SHOWN into the wiki's password form field (use copy and paste
 118 +for that).
 119 +
 120 +After successfully logging in, it is of course a good idea to set a new and known password.
 121 +""" + text
 122 +
 123 +            if self.options.comment:
 124 +               text = self.options.comment + '\n\n' + text
 125 +
 126 +            mailok, msg = mail.sendmail(request, [self.options.email], subject,
 127 +                                        text, mail_from=cfg.mail_from or "Wiki")
 128 +            print "- send OK"
 129 +        else:
 130 +            print "- Can't send, because users email does not exist"
 131 +
 132 +
moin_patch_20061104.txt

moin --config-dir=mywiki_path --wiki-url=mywiki_url account sendmail --email=you@somewhere \
 --comment="This mail is to inform you about your account data for the blablabla project"

results then in an email:

This mail is to inform you about your account data for the blablabla project

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.

Login Name: YouSomewhere

Login Password: {SHA}00ERDFGHFGWESPASS=

Login URL: http://mywiki-url/mywiki?action=login


CategoryFeatureRequest

MoinMoin: FeatureRequests/MoinSendMailAndCreateShouldCreateAlwaysAPassword (last edited 2007-10-29 19:06:24 by localhost)