view data/plugin/script/account/ @ 653:127da830be6c

updated copyright
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Tue, 19 Apr 2016 16:29:54 +0200
parents ca006bf7dae8
line wrap: on
line source
# -*- coding: iso-8859-1 -*-
MoinMoin - create a user account

@copyright: 2006 MoinMoin:ThomasWaldmann,
            2011-2016 MoinMoin:ReimarBauer
@license: GNU GPL, see COPYING for details.
import sys
    from pwgen import pwgen
except ImportError:
    print '!!!'
    print 'You need to "pip install pwgen"'
    print '('
    print '!!!'
from MoinMoin.script import MoinScript
from MoinMoin import user

class PluginScript(MoinScript):
This tool allows you to create many accounts via a command line interface.

Detailed Instructions:
General syntax: moin [options] account create [create-options]

[options] usually should be:
    --config-dir=/path/to/my/cfg/ --wiki-url=

[create-options] see below:
    1. Verify that you have specified the right options.
       This script does no verification of email addresses or the like.

    2. To create users you need an input file: with lines of Wiki UserName, EMAIL
       moin ... account create --filename input_file.csv

    def __init__(self, argv, def_values):
        MoinScript.__init__(self, argv, def_values)
            "--filename", metavar="filename", dest="filename",
            help="comma separated file of WikiUsername, email."

    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.filename
        if not flags_given:

        request = self.request

        text = file(self.options.filename, 'r').read()
        lines = text.split('\n')
        for line in lines:
                uname, email = line.split(',')
                uname = uname.strip()
                email = email.strip()
                if '@' in email:
                    password = pwgen(10, no_symbols=True)
                    if user.User(request, name=uname).exists():
                        print 'This username "%s" exists already!' % uname
                    # Email should be unique - see also MoinMoin.action.newaccount
                    if email and request.cfg.user_email_unique:
                        if user.get_by_email_address(request, email):
                            print 'This emailaddress "%s" belongs to someone else!' % email
                    u = user.User(request, None, uname, password=password)
           = email
                    u.aliasname = ''
                    print " %-20s %-25s %-35s" % (,,,
                    print "- created."

            except ValueError:
                print line