# HG changeset patch # User ReimarBauer # Node ID 7937d0ddbc414c30a245d0ad209812b2fe768c40 # Parent 96706051ff4eac5872a1986cbd83e92cccb214c8 sendmail feature added to send an invitation. sendmail does have an optional --comment key to add some text for an invitation. create was changed to create always a password if non was submitted. diff -r 96706051ff4e -r 7937d0ddbc41 MoinMoin/script/_util.py --- a/MoinMoin/script/_util.py Sat Oct 28 19:29:25 2006 +0200 +++ b/MoinMoin/script/_util.py Fri Nov 03 17:35:08 2006 +0100 @@ -130,6 +130,7 @@ class MoinScript(Script): moin ... account check ... moin ... account create ... +moin ... account sendmail ... moin ... account disable ... moin ... cli show ... diff -r 96706051ff4e -r 7937d0ddbc41 MoinMoin/script/account/create.py --- a/MoinMoin/script/account/create.py Sat Oct 28 19:29:25 2006 +0200 +++ b/MoinMoin/script/account/create.py Fri Nov 03 17:35:08 2006 +0100 @@ -43,6 +43,18 @@ class PluginScript(MoinScript): request = self.request from MoinMoin import user, wikiutil + if not self.options.password: + import time, sha + from random import randint + import base64 + + charset = 'utf-8' + pwd = "%s%d" % (str(time.time()), randint(0, 65535)) + pwd = pwd.encode(charset) + pwd = sha.new(pwd).digest() + pwd = '{SHA}%s' % base64.encodestring(pwd).rstrip() + self.options.password = pwd + u = user.User(request, None, self.options.uname, password=self.options.password) u.email = self.options.email u.aliasname = self.options.ualiasname or '' diff -r 96706051ff4e -r 7937d0ddbc41 MoinMoin/script/account/sendmail.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MoinMoin/script/account/sendmail.py Fri Nov 03 17:35:08 2006 +0100 @@ -0,0 +1,88 @@ +# -*- coding: iso-8859-1 -*- +""" + MoinMoin - invite a user by sending the account data + + @copyright: 2006 by MoinMoin:ReimarBauer + @license: GNU GPL, see COPYING for details. +""" +from MoinMoin import user, wikiutil +from MoinMoin.script._util import MoinScript +from MoinMoin.util import mail + +class PluginScript(MoinScript): + def __init__(self, argv, def_values): + MoinScript.__init__(self, argv, def_values) + self.parser.add_option( + "--email", metavar="EMAIL", dest="email", + help="Set the user's email address to EMAIL." + ) + self.parser.add_option( + "--comment", metavar="comment", dest="comment", + help="adds a comment to the mailbody." + ) + + def get_user(self): + users = user.getUserList(self.request) + for uid in users: + theuser = user.User(self.request, uid) + if theuser.valid and theuser.email.lower() == self.options.email.lower(): + return theuser + + def check_user(self): + users = user.getUserList(self.request) + for uid in users: + theuser = user.User(self.request, uid) + if theuser.valid and theuser.email.lower() == self.options.email.lower(): + return True + return False + + def mainloop(self): + # we don't expect non-option arguments + if len(self.args) != 0: + self.parser.error("incorrect number of arguments") + + flags_given = self.options.email + if not flags_given: + self.parser.print_help() + import sys + sys.exit(1) + + self.init_request() + request = self.request + cfg = request.cfg + + if self.check_user(): + theuser = self.get_user() + if len(theuser.enc_password) == 0: + print "- Can't invite check the passowrd of this user %s" % (theuser.name) + return + + subject = ('[%(sitename)s] Your wiki account data') % {'sitename': self.options.wiki_url or "Wiki"} + text = 'Welcome to the Wiki' + + text = '\n' + """\ +Login Name: %s + +Login Password: %s + +Login URL: %s/?action=login + """ % (theuser.name, theuser.enc_password, self.options.wiki_url) + + text = """\ +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. +""" + text + + if self.options.comment: + text = self.options.comment + '\n\n' + text + + mailok, msg = mail.sendmail(request, [self.options.email], subject, + text, mail_from=cfg.mail_from or "Wiki") + print "- send OK" + else: + print "- Can't send, because users email does not exist" + +