Skip to content

Commit e3d6b1f

Browse files
author
Richard Jones
committed
reinstated registration, cleaned up PT compile error reporting
1 parent bf7593c commit e3d6b1f

File tree

5 files changed

+120
-34
lines changed

5 files changed

+120
-34
lines changed

TODO.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ New templating TODO:
4747
. generic class editing
4848
. classhelp
4949
. query saving
50+
- add ":queryname" to search form submission, and handle it in search action
51+
- ?add a drop-down on search page with all queries that fills form with
52+
each query's values?
5053
. search "refinement" (pre-fill the search page with the current search
5154
parameters)
52-
. web registration of new users by anonymous
5355

5456
ongoing: any bugs
5557

roundup/cgi/client.py

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: client.py,v 1.4 2002-09-01 22:09:20 richard Exp $
1+
# $Id: client.py,v 1.5 2002-09-01 23:57:53 richard Exp $
22

33
__doc__ = """
44
WWW request handler (also used in the stand-alone server).
@@ -289,7 +289,7 @@ def template(self, name, **kwargs):
289289
return pt.render(**kwargs)
290290
except PageTemplate.PTRuntimeError, message:
291291
return '<strong>%s</strong><ol>%s</ol>'%(message,
292-
cgi.escape('<li>'.join(pt._v_errors)))
292+
'<li>'.join(pt._v_errors))
293293
except:
294294
# everything else
295295
return cgitb.html()
@@ -306,9 +306,9 @@ def content(self):
306306
actions = {
307307
'edit': 'editItemAction',
308308
'new': 'newItemAction',
309+
'register': 'registerAction',
309310
'login': 'login_action',
310311
'logout': 'logout_action',
311-
'register': 'register_action',
312312
'search': 'searchAction',
313313
}
314314
def handle_action(self):
@@ -319,9 +319,9 @@ def handle_action(self):
319319
actions are defined in the "actions" dictionary on this class:
320320
"edit" -> self.editItemAction
321321
"new" -> self.newItemAction
322+
"register" -> self.registerAction
322323
"login" -> self.login_action
323324
"logout" -> self.logout_action
324-
"register" -> self.register_action
325325
"search" -> self.searchAction
326326
327327
'''
@@ -472,17 +472,25 @@ def logout_action(self):
472472
# Let the user know what's going on
473473
self.ok_message.append(_('You are logged out'))
474474

475-
def register_action(self):
475+
def registerAction(self):
476476
'''Attempt to create a new user based on the contents of the form
477477
and then set the cookie.
478478
479479
return 1 on successful login
480480
'''
481+
# create the new user
482+
cl = self.db.user
483+
484+
# parse the props from the form
485+
try:
486+
props = parsePropsFromForm(self.db, cl, self.form, self.nodeid)
487+
except (ValueError, KeyError), message:
488+
self.error_message.append(_('Error: ') + str(message))
489+
return
490+
481491
# make sure we're allowed to register
482-
userid = self.db.user.lookup(self.user)
483-
if not self.db.security.hasPermission('Web Registration', userid):
484-
raise Unauthorised, _("You do not have permission to access"\
485-
" %(action)s.")%{'action': 'registration'}
492+
if not self.registerPermission(props):
493+
raise Unauthorised, _("You do not have permission to register")
486494

487495
# re-open the database as "admin"
488496
if self.user != 'admin':
@@ -493,21 +501,33 @@ def register_action(self):
493501
try:
494502
props = parsePropsFromForm(self.db, cl, self.form)
495503
props['roles'] = self.instance.NEW_WEB_USER_ROLES
496-
uid = cl.create(**props)
504+
self.userid = cl.create(**props)
497505
self.db.commit()
498506
except ValueError, message:
499507
self.error_message.append(message)
500508

501509
# log the new user in
502-
self.user = cl.get(uid, 'username')
510+
self.user = cl.get(self.userid, 'username')
503511
# re-open the database for real, using the user
504512
self.opendb(self.user)
505-
password = cl.get(uid, 'password')
513+
password = self.db.user.get(self.userid, 'password')
506514
self.set_cookie(self.user, password)
507515

508516
# nice message
509517
self.ok_message.append(_('You are now registered, welcome!'))
510518

519+
def registerPermission(self, props):
520+
''' Determine whether the user has permission to register
521+
522+
Base behaviour is to check the user has "Web Registration".
523+
'''
524+
# registration isn't allowed to supply roles
525+
if props.has_key('roles'):
526+
return 0
527+
if self.db.security.hasPermission('Web Registration', self.userid):
528+
return 1
529+
return 0
530+
511531
def editItemAction(self):
512532
''' Perform an edit of an item in the database.
513533
@@ -589,10 +609,9 @@ def editItemPermission(self, props):
589609
# if the item being edited is the current user, we're ok
590610
if self.nodeid == self.userid:
591611
return 1
592-
if not self.db.security.hasPermission('Edit', self.userid,
593-
self.classname):
594-
return 0
595-
return 1
612+
if self.db.security.hasPermission('Edit', self.userid, self.classname):
613+
return 1
614+
return 0
596615

597616
def newItemAction(self):
598617
''' Add a new item to the database.
@@ -663,9 +682,9 @@ def newItemPermission(self, props):
663682
if self.classname == 'user' and has('Web Registration', self.userid,
664683
'user'):
665684
return 1
666-
if not has('Edit', self.userid, self.classname):
667-
return 0
668-
return 1
685+
if has('Edit', self.userid, self.classname):
686+
return 1
687+
return 0
669688

670689
def genericEditAction(self):
671690
''' Performs an edit of all of a class' items in one go.

roundup/templates/classic/html/page

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,22 @@
3939
<a href="user?:template=item">Add User</a>
4040
</p>
4141

42-
<p class="userblock">
43-
<b>Hello,</b><br><b tal:content="request/user/username">username</b><br>
44-
<form method="POST" action=''
45-
tal:condition="python:request.user.username=='anonymous'">
42+
<p class="userblock" tal:condition="python:request.user.username=='anonymous'">
43+
<form method="POST" action="">
4644
<input size="10" name="__login_name"><br>
4745
<input size="10" type="password" name="__login_password"><br>
4846
<input type="submit" name=":action" value="login">
4947
<span tal:replace="structure request/indexargs_form" />
5048
</form>
51-
<tal:block tal:condition="python:request.user.username != 'anonymous'">
52-
<a tal:attributes="href string:issue?:sort=-activity&:group=priority&:filter=status,assignedto&:columns=id,activity,title,creator,priority&status=-1,1,2,3,4,5,6,7&assignedto=${request/user/id}">My Issues</a><br>
53-
<a tal:attributes="href string:user${request/user/id}">My Details</a><br>
54-
<a tal:attributes="href python:request.indexargs_href(request.url,
55-
{':action':'logout'})">Logout</a>
56-
</tal:block>
49+
<a href="user?:template=register">Register</a>
50+
</p>
51+
52+
<p class="userblock" tal:condition="python:request.user.username != 'anonymous'">
53+
<b>Hello,</b><br><b tal:content="request/user/username">username</b><br>
54+
<a tal:attributes="href string:issue?:sort=-activity&:group=priority&:filter=status,assignedto&:columns=id,activity,title,creator,priority&status=-1,1,2,3,4,5,6,7&assignedto=${request/user/id}">My Issues</a><br>
55+
<a tal:attributes="href string:user${request/user/id}">My Details</a><br>
56+
<a tal:attributes="href python:request.indexargs_href(request.url,
57+
{':action':'logout'})">Logout</a>
5758
</p>
5859
</td>
5960
<td>

roundup/templates/classic/html/user.item

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<!-- dollarId: user.item,v 1.7 2002/08/16 04:29:04 richard Exp dollar-->
2-
<tal:block tal:define="editok python:request.user.hasPermission('Edit') or
3-
user.id == request.user.id;
4-
viewok python:request.user.hasPermission('View')">
2+
<tal:block tal:define="
3+
editok python:request.user.hasPermission('Edit') or
4+
user.id == request.user.id;
5+
viewok python:request.user.hasPermission('View')">
56

67
<span tal:condition="python:not (viewok or editok)">
78
You are not allowed to view this page.
@@ -50,7 +51,7 @@ You are not allowed to view this page.
5051

5152
<tr>
5253
<td>&nbsp;</td>
53-
<td colspan=3 tal:content="structure user/submit">submit button here</td>
54+
<td tal:content="structure user/submit">submit button here</td>
5455
</tr>
5556
</table>
5657
</form>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<!-- dollarId: user.item,v 1.7 2002/08/16 04:29:04 richard Exp dollar-->
2+
<tal:block tal:define=" editok python:request.user.username=='anonymous' and
3+
request.user.hasPermission('Web Registration')">
4+
5+
<span tal:condition="python:not editok">
6+
You are not allowed to view this page.
7+
</span>
8+
9+
<tal:block tal:condition="editok">
10+
<form method="POST" onSubmit="return submit_once()" enctype="multipart/form-data">
11+
12+
<table class="form">
13+
<tr>
14+
<th>Name</th>
15+
<td tal:content="structure user/realname/field">realname</td>
16+
</tr>
17+
<tr>
18+
<th>Login Name</th>
19+
<td tal:content="structure user/username/field">username</td>
20+
</tr>
21+
<tr>
22+
<th>Login Password</th>
23+
<td tal:content="structure user/password/field">password</td>
24+
</tr>
25+
<tr tal:condition="python:request.user.hasPermission('Web Roles')">
26+
<th>Roles</th>
27+
<td tal:condition="exists:item"
28+
tal:content="structure user/roles/field">roles</td>
29+
<td tal:condition="not:exists:item">
30+
<input name="roles" tal:attributes="value db/config/NEW_WEB_USER_ROLES">
31+
</td>
32+
</tr>
33+
<tr>
34+
<th>Phone</th>
35+
<td tal:content="structure user/phone/field">phone</td>
36+
</tr>
37+
<tr>
38+
<th>Organisation</th>
39+
<td tal:content="structure user/organisation/field">organisation</td>
40+
</tr>
41+
<tr>
42+
<th>E-mail address</th>
43+
<td tal:content="structure user/address/field">address</td>
44+
</tr>
45+
<tr>
46+
<th>Alternate E-mail addresses<br>One address per line</th>
47+
<td tal:content="structure user/alternate_addresses/multiline">alternate_addresses</td>
48+
</tr>
49+
50+
<tr>
51+
<td>&nbsp;</td>
52+
<td>
53+
<input type="hidden" name=":action" value="register">
54+
<input type="submit" name="submit" value="Register">
55+
</td>
56+
</tr>
57+
</table>
58+
</form>
59+
60+
</tal:block>
61+
62+
</tal:block>
63+

0 commit comments

Comments
 (0)