annotate MoinMoin/script/account/create.py @ 3884:085328cb4f4d

script.account create, disable, resetpw: checks for already existing user (backport from 1.8)
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sat, 19 Jul 2008 23:15:59 +0200
parents 2572688e031a
children f85cd27073a9
rev   line source
501
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
2 """
3108
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
3 MoinMoin - create a user account
501
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
4
3108
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
5 @copyright: 2006 MoinMoin:ThomasWaldmann
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
6 @license: GNU GPL, see COPYING for details.
501
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
7 """
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
8
670
687633456631 MoinMoin.script: move _util stuff to __init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 501
diff changeset
9 from MoinMoin.script import MoinScript
501
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
10
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
11 class PluginScript(MoinScript):
3108
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
12 """\
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
13 Purpose:
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
14 ========
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
15 This tool allows you to create user accounts via a command line interface.
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
16
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
17 Detailed Instructions:
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
18 ======================
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
19 General syntax: moin [options] account create [create-options]
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
20
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
21 [options] usually should be:
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
22 --config-dir=/path/to/my/cfg/ --wiki-url=wiki.example.org/
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
23
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
24 [create-options] see below:
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
25 1. Verify that you have specified the right options.
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
26 This script does no verification of email addresses or the like.
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
27
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
28 2. To create a normal user 'JohnSmith' with an alias of 'JSmith' and an
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
29 email of 'john@smith.com'
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
30 moin ... account create --name JohnSmith --alias JSmith --email john@smith.com
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
31 """
2572688e031a improved moin script's builtin help function, thanks to Federico Lorenzi (ported from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
32
501
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
33 def __init__(self, argv, def_values):
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
34 MoinScript.__init__(self, argv, def_values)
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
35 self.parser.add_option(
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
36 "--name", metavar="NAME", dest="uname",
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
37 help="Set the wiki user name to NAME."
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
38 )
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
39 self.parser.add_option(
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
40 "--alias", metavar="ALIAS", dest="ualiasname",
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
41 help="Set the wiki user alias name to ALIAS (e.g. the real name if NAME is cryptic)."
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
42 )
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
43 self.parser.add_option(
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
44 "--email", metavar="EMAIL", dest="email",
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
45 help="Set the user's email address to EMAIL."
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
46 )
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
47 self.parser.add_option(
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
48 "--password", metavar="PASSWORD", dest="password",
3884
085328cb4f4d script.account create, disable, resetpw: checks for already existing user (backport from 1.8)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3108
diff changeset
49 help="Set the user's password to PASSWORD."
501
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
50 )
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
51
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
52 def mainloop(self):
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
53 # we don't expect non-option arguments
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
54 if len(self.args) != 0:
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
55 self.parser.error("incorrect number of arguments")
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
56
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
57 flags_given = self.options.uname and self.options.email
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
58 if not flags_given:
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
59 self.parser.print_help()
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
60 import sys
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
61 sys.exit(1)
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
62
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
63 self.init_request()
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
64 request = self.request
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
65
1791
6dd2e29acffe Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 670
diff changeset
66 from MoinMoin import user
3884
085328cb4f4d script.account create, disable, resetpw: checks for already existing user (backport from 1.8)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3108
diff changeset
67 if user.User(request, name=self.options.uname).exists():
085328cb4f4d script.account create, disable, resetpw: checks for already existing user (backport from 1.8)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3108
diff changeset
68 print 'This username "%s" exists already!' % self.options.uname
085328cb4f4d script.account create, disable, resetpw: checks for already existing user (backport from 1.8)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3108
diff changeset
69 return
085328cb4f4d script.account create, disable, resetpw: checks for already existing user (backport from 1.8)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3108
diff changeset
70 # Email should be unique - see also MoinMoin.action.newaccount
085328cb4f4d script.account create, disable, resetpw: checks for already existing user (backport from 1.8)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3108
diff changeset
71 if self.options.email and request.cfg.user_email_unique:
085328cb4f4d script.account create, disable, resetpw: checks for already existing user (backport from 1.8)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3108
diff changeset
72 if user.get_by_email_address(request, self.options.email):
085328cb4f4d script.account create, disable, resetpw: checks for already existing user (backport from 1.8)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3108
diff changeset
73 print 'This emailaddress "%s" belongs to someone else!' % self.options.email
085328cb4f4d script.account create, disable, resetpw: checks for already existing user (backport from 1.8)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3108
diff changeset
74 return
501
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
75 u = user.User(request, None, self.options.uname, password=self.options.password)
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
76 u.email = self.options.email
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
77 u.aliasname = self.options.ualiasname or ''
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
78 print " %-20s %-25s %-35s" % (u.id, u.name, u.email),
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
79 u.save()
069acf15d7b3 moin account {check,create,disable} script commands
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
80 print "- created."