Attachment 'createuser.patch'
Download 1 diff -ur MoinMoin/multiconfig.py MoinMoin2/multiconfig.py
2 --- MoinMoin/multiconfig.py 2005-03-12 15:26:14.000000000 -0600
3 +++ MoinMoin2/multiconfig.py 2005-03-25 03:59:12.498181700 -0600
4 @@ -155,6 +155,7 @@
5 acl_rights_default = u"Trusted:read,write,delete,revert Known:read,write,delete,revert All:read,write"
6 acl_rights_before = u""
7 acl_rights_after = u""
8 + acl_rights_createuser = u"All:write"
9 acl_rights_valid = ['read', 'write', 'delete', 'revert', 'admin']
10
11 allow_extended_names = 1
12 diff -ur MoinMoin/userform.py MoinMoin2/userform.py
13 --- MoinMoin/userform.py 2005-03-06 16:15:42.000000000 -0600
14 +++ MoinMoin2/userform.py 2005-03-26 07:09:47.481875000 -0600
15 @@ -7,7 +7,7 @@
16 """
17
18 import string, time, re, Cookie
19 -from MoinMoin import config, user, util, wikiutil
20 +from MoinMoin import config, user, util, wikiutil, wikiacl
21 from MoinMoin.util import web, mail, datetime
22 from MoinMoin.widget import html
23
24 @@ -142,6 +142,8 @@
25 self.request.setCookie()
26
27 else:
28 + createuseracl = wikiacl.CreateUserAccessControlList(self.request).may(self.request, self.request.user.name, "write")
29 +
30 # Save user profile
31 theuser = user.User(self.request)
32
33 @@ -160,12 +162,29 @@
34 # Is this an existing user trying to change information or a new user?
35 # Name required to be unique. Check if name belong to another user.
36 newuser = 1
37 - if user.getUserId(self.request, theuser.name):
38 - if theuser.name != self.request.user.name:
39 - return _("This user name already belongs to somebody else.")
40 +
41 + # create key is for existing users creating new users
42 + # save key is for users creating or updating themselves
43 + if form.has_key('save'):
44 + if user.getUserId(self.request, theuser.name):
45 + if theuser.name != self.request.user.name:
46 + return _("This user name already belongs to somebody else.")
47 else:
48 newuser = 0
49
50 + # Now that we know if it's a new user or not, we can check the acl
51 + if newuser and not createuseracl:
52 + return _("You are not allowed to create a user account.")
53 +
54 + # create key is for existing users creating new users
55 + # save key is for users creating or updating themselves
56 + if newuser and form.has_key('create'):
57 + theuserisnew = self.request
58 + theuserisnew.saved_cookie = ''
59 + theuserisnew.auth_username = ''
60 + theuser = user.User(theuserisnew)
61 + theuser.name = form['username'][0]
62 +
63 # try to get the password and pw repeat
64 password = form.get('password', [''])[0]
65 password2 = form.get('password2',[''])[0]
66 @@ -256,8 +275,12 @@
67
68 # save data and send cookie
69 theuser.save()
70 - self.request.user = theuser
71 - self.request.setCookie()
72 +
73 + # create key is for existing users creating new users
74 + # save key is for users creating or updating themselves
75 + if form.has_key('save'):
76 + self.request.user = theuser
77 + self.request.setCookie()
78
79 result = _("User preferences saved!")
80 if _debug:
81 @@ -382,20 +405,25 @@
82 _ = self._
83 self.make_form()
84
85 + createuseracl = wikiacl.CreateUserAccessControlList(self.request).may(self.request, self.request.user.name, "write")
86 +
87 if self.request.user.valid:
88 # User preferences interface
89 buttons = [
90 - ('save', _('Save')),
91 - ('logout', _('Logout')),
92 - ]
93 + ('save', _('Save'))
94 + ]
95 + if createuseracl:
96 + buttons.append(('create', _('Create Profile')))
97 + buttons.append(('logout', _('Logout')))
98 else:
99 # Login / register interface
100 buttons = [
101 # IMPORTANT: login should be first to be the default
102 # button when a user click enter.
103 ('login', _('Login')),
104 - ("save", _('Create Profile')),
105 ]
106 + if createuseracl:
107 + buttons.append(("save", _('Create Profile')))
108 if self.cfg.mail_smarthost:
109 buttons.append(("login_sendmail", _('Mail me my account data')))
110
111 @@ -413,19 +441,29 @@
112 ' ',
113 ])
114
115 - self.make_row(_('Password repeat'), [
116 - html.INPUT(
117 - type="password", size="36", name="password2",
118 - ),
119 - ' ', _('(Only when changing passwords)'),
120 - ])
121 + if self.request.user.valid or createuseracl:
122 + self.make_row(_('Password repeat'), [
123 + html.INPUT(
124 + type="password", size="36", name="password2",
125 + ),
126 + ' ', _('(Only when changing passwords)'),
127 + ])
128 +
129 + if self.cfg.mail_smarthost and not createuseracl:
130 + self.make_row(_('Email'), [
131 + html.INPUT(
132 + type="text", size="36", name="email", value=self.request.user.email
133 + ),
134 + ' ', _('(Only for mailing your account data)', formatted=False),
135 + ])
136 + elif createuseracl:
137 + self.make_row(_('Email'), [
138 + html.INPUT(
139 + type="text", size="36", name="email", value=self.request.user.email
140 + ),
141 + ' ',
142 + ])
143
144 - self.make_row(_('Email'), [
145 - html.INPUT(
146 - type="text", size="36", name="email", value=self.request.user.email
147 - ),
148 - ' ',
149 - ])
150
151 # Show options only if already logged in
152 if self.request.user.valid:
153 diff -ur MoinMoin/wikiacl.py MoinMoin2/wikiacl.py
154 --- MoinMoin/wikiacl.py 2005-01-09 12:48:07.000000000 -0600
155 +++ MoinMoin2/wikiacl.py 2005-03-25 03:54:21.091931700 -0600
156 @@ -357,3 +357,28 @@
157 acl_lines.append(args)
158 return AccessControlList(request, acl_lines)
159
160 +class CreateUserAccessControlList(AccessControlList):
161 + ''' Access Control List for Creating Users
162 +
163 + Control who may create new user accounts on the system
164 +
165 + Configuration options
166 +
167 + cfg.acl_rights_createuser
168 + Defines who is able to create users. Permission is either
169 + "write" or nothing.
170 + Default: "All:write"
171 +
172 + '''
173 +
174 + def __init__(self, request):
175 + """Initialize an ACL, starting from <nothing>.
176 + """
177 + self.setLines(request.cfg)
178 +
179 + def setLines(self, cfg):
180 + self.clean()
181 + self.addCreateuser(cfg)
182 +
183 + def addCreateuser(self, cfg):
184 + self.addLine(cfg, cfg.acl_rights_createuser, remember=0)
185
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.