Skip to content

Commit ced1f68

Browse files
author
Johannes Gijsbers
committed
Extract confirm_registration() from client to roundupdb...
...for use in mailgw registration confirmation.
1 parent 81ac36c commit ced1f68

File tree

3 files changed

+43
-34
lines changed

3 files changed

+43
-34
lines changed

roundup/backends/back_anydbm.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: back_anydbm.py,v 1.124 2003-09-04 00:47:01 richard Exp $
18+
#$Id: back_anydbm.py,v 1.125 2003-09-06 07:27:30 jlgijsbers Exp $
1919
'''
2020
This module defines a backend that saves the hyperdatabase in a database
2121
chosen by anydbm. It is guaranteed to always be available in python
@@ -87,8 +87,10 @@ def post_init(self):
8787
# reindex the db if necessary
8888
if self.indexer.should_reindex():
8989
self.reindex()
90+
self.figure_curuserid()
9091

91-
# figure the "curuserid"
92+
def figure_curuserid(self):
93+
"""Figure out the 'curuserid'."""
9294
if self.journaltag is None:
9395
self.curuserid = None
9496
elif self.journaltag == 'admin':

roundup/cgi/client.py

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: client.py,v 1.132 2003-08-28 04:46:39 richard Exp $
1+
# $Id: client.py,v 1.133 2003-09-06 07:27:30 jlgijsbers Exp $
22

33
__doc__ = """
44
WWW request handler (also used in the stand-alone server).
@@ -840,41 +840,16 @@ def registerPermission(self, props):
840840
def confRegoAction(self):
841841
''' Grab the OTK, use it to load up the new user details
842842
'''
843-
# pull the rego information out of the otk database
844-
otk = self.form['otk'].value
845-
props = self.db.otks.getall(otk)
846-
for propname, proptype in self.db.user.getprops().items():
847-
value = props.get(propname, None)
848-
if value is None:
849-
pass
850-
elif isinstance(proptype, hyperdb.Date):
851-
props[propname] = date.Date(value)
852-
elif isinstance(proptype, hyperdb.Interval):
853-
props[propname] = date.Interval(value)
854-
elif isinstance(proptype, hyperdb.Password):
855-
props[propname] = password.Password()
856-
props[propname].unpack(value)
857-
858-
# re-open the database as "admin"
859-
if self.user != 'admin':
860-
self.opendb('admin')
861-
862-
# create the new user
863-
cl = self.db.user
864-
# XXX we need to make the "default" page be able to display errors!
865843
try:
866-
props['roles'] = self.instance.config.NEW_WEB_USER_ROLES
867-
del props['__time']
868-
self.userid = cl.create(**props)
869-
# clear the props from the otk database
870-
self.db.otks.destroy(otk)
871-
self.db.commit()
844+
# pull the rego information out of the otk database
845+
self.userid = self.db.confirm_registration(self.form['otk'].value)
872846
except (ValueError, KeyError), message:
847+
# XXX: we need to make the "default" page be able to display errors!
873848
self.error_message.append(str(message))
874849
return
875-
850+
876851
# log the new user in
877-
self.user = cl.get(self.userid, 'username')
852+
self.user = self.db.user.get(self.userid, 'username')
878853
# re-open the database for real, using the user
879854
self.opendb(self.user)
880855

roundup/roundupdb.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: roundupdb.py,v 1.86 2003-04-27 02:24:37 richard Exp $
18+
# $Id: roundupdb.py,v 1.87 2003-09-06 07:27:30 jlgijsbers Exp $
1919

2020
__doc__ = """
2121
Extending hyperdb with types specific to issue-tracking.
@@ -27,6 +27,8 @@
2727

2828
from rfc2822 import encode_header
2929

30+
from roundup import password, date
31+
3032
# if available, use the 'email' module, otherwise fallback to 'rfc822'
3133
try :
3234
from email.Utils import formataddr as straddr
@@ -70,6 +72,36 @@ def getUserTimezone(self):
7072
timezone = 0
7173
return timezone
7274

75+
def confirm_registration(self, otk):
76+
props = self.otks.getall(otk)
77+
for propname, proptype in self.user.getprops().items():
78+
value = props.get(propname, None)
79+
if value is None:
80+
pass
81+
elif isinstance(proptype, hyperdb.Date):
82+
props[propname] = date.Date(value)
83+
elif isinstance(proptype, hyperdb.Interval):
84+
props[propname] = date.Interval(value)
85+
elif isinstance(proptype, hyperdb.Password):
86+
props[propname] = password.Password()
87+
props[propname].unpack(value)
88+
89+
# tag new user creation with 'admin'
90+
self.journaltag = 'admin'
91+
self.figure_curuserid()
92+
93+
# create the new user
94+
cl = self.user
95+
96+
props['roles'] = self.config.NEW_WEB_USER_ROLES
97+
del props['__time']
98+
userid = cl.create(**props)
99+
# clear the props from the otk database
100+
self.otks.destroy(otk)
101+
self.commit()
102+
103+
return userid
104+
73105
class MessageSendError(RuntimeError):
74106
pass
75107

0 commit comments

Comments
 (0)