comparison 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
comparison
equal deleted inserted replaced
3882:c8ffd029ab1f 3884:085328cb4f4d
20 20
21 [options] usually should be: 21 [options] usually should be:
22 --config-dir=/path/to/my/cfg/ --wiki-url=wiki.example.org/ 22 --config-dir=/path/to/my/cfg/ --wiki-url=wiki.example.org/
23 23
24 [create-options] see below: 24 [create-options] see below:
25 0. Verify that the account does not exist.
26 Currently this script does not check if the user exists.
27
28 1. Verify that you have specified the right options. 25 1. Verify that you have specified the right options.
29 This script does no verification of email addresses or the like. 26 This script does no verification of email addresses or the like.
30 27
31 2. To create a normal user 'JohnSmith' with an alias of 'JSmith' and an 28 2. To create a normal user 'JohnSmith' with an alias of 'JSmith' and an
32 email of 'john@smith.com' 29 email of 'john@smith.com'
47 "--email", metavar="EMAIL", dest="email", 44 "--email", metavar="EMAIL", dest="email",
48 help="Set the user's email address to EMAIL." 45 help="Set the user's email address to EMAIL."
49 ) 46 )
50 self.parser.add_option( 47 self.parser.add_option(
51 "--password", metavar="PASSWORD", dest="password", 48 "--password", metavar="PASSWORD", dest="password",
52 help="Set the user's password to PASSWORD (either cleartext or {SHA1}...)." 49 help="Set the user's password to PASSWORD."
53 ) 50 )
54 51
55 def mainloop(self): 52 def mainloop(self):
56 # we don't expect non-option arguments 53 # we don't expect non-option arguments
57 if len(self.args) != 0: 54 if len(self.args) != 0:
65 62
66 self.init_request() 63 self.init_request()
67 request = self.request 64 request = self.request
68 65
69 from MoinMoin import user 66 from MoinMoin import user
67 if user.User(request, name=self.options.uname).exists():
68 print 'This username "%s" exists already!' % self.options.uname
69 return
70 # Email should be unique - see also MoinMoin.action.newaccount
71 if self.options.email and request.cfg.user_email_unique:
72 if user.get_by_email_address(request, self.options.email):
73 print 'This emailaddress "%s" belongs to someone else!' % self.options.email
74 return
70 u = user.User(request, None, self.options.uname, password=self.options.password) 75 u = user.User(request, None, self.options.uname, password=self.options.password)
71 u.email = self.options.email 76 u.email = self.options.email
72 u.aliasname = self.options.ualiasname or '' 77 u.aliasname = self.options.ualiasname or ''
73 print " %-20s %-25s %-35s" % (u.id, u.name, u.email), 78 print " %-20s %-25s %-35s" % (u.id, u.name, u.email),
74 u.save() 79 u.save()