From: jlgijsbers Date: Sat, 6 Sep 2003 07:27:30 +0000 (+0000) Subject: Extract confirm_registration() from client to roundupdb, for use in mailgw X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=f268b1dbdf9576144e62fd491f0095019becd7ad;p=roundup.git Extract confirm_registration() from client to roundupdb, for use in mailgw registration confirmation. git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1857 57a73879-2fb5-44c3-a270-3262357dd7e2 --- diff --git a/roundup/backends/back_anydbm.py b/roundup/backends/back_anydbm.py index b0a8556..86b2510 100644 --- a/roundup/backends/back_anydbm.py +++ b/roundup/backends/back_anydbm.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -#$Id: back_anydbm.py,v 1.124 2003-09-04 00:47:01 richard Exp $ +#$Id: back_anydbm.py,v 1.125 2003-09-06 07:27:30 jlgijsbers Exp $ ''' This module defines a backend that saves the hyperdatabase in a database chosen by anydbm. It is guaranteed to always be available in python @@ -87,8 +87,10 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database): # reindex the db if necessary if self.indexer.should_reindex(): self.reindex() + self.figure_curuserid() - # figure the "curuserid" + def figure_curuserid(self): + """Figure out the 'curuserid'.""" if self.journaltag is None: self.curuserid = None elif self.journaltag == 'admin': diff --git a/roundup/cgi/client.py b/roundup/cgi/client.py index 6dce8d5..694ec1b 100644 --- a/roundup/cgi/client.py +++ b/roundup/cgi/client.py @@ -1,4 +1,4 @@ -# $Id: client.py,v 1.132 2003-08-28 04:46:39 richard Exp $ +# $Id: client.py,v 1.133 2003-09-06 07:27:30 jlgijsbers Exp $ __doc__ = """ WWW request handler (also used in the stand-alone server). @@ -840,41 +840,16 @@ please visit the following URL: def confRegoAction(self): ''' Grab the OTK, use it to load up the new user details ''' - # pull the rego information out of the otk database - otk = self.form['otk'].value - props = self.db.otks.getall(otk) - for propname, proptype in self.db.user.getprops().items(): - value = props.get(propname, None) - if value is None: - pass - elif isinstance(proptype, hyperdb.Date): - props[propname] = date.Date(value) - elif isinstance(proptype, hyperdb.Interval): - props[propname] = date.Interval(value) - elif isinstance(proptype, hyperdb.Password): - props[propname] = password.Password() - props[propname].unpack(value) - - # re-open the database as "admin" - if self.user != 'admin': - self.opendb('admin') - - # create the new user - cl = self.db.user -# XXX we need to make the "default" page be able to display errors! try: - props['roles'] = self.instance.config.NEW_WEB_USER_ROLES - del props['__time'] - self.userid = cl.create(**props) - # clear the props from the otk database - self.db.otks.destroy(otk) - self.db.commit() + # pull the rego information out of the otk database + self.userid = self.db.confirm_registration(self.form['otk'].value) except (ValueError, KeyError), message: + # XXX: we need to make the "default" page be able to display errors! self.error_message.append(str(message)) return - + # log the new user in - self.user = cl.get(self.userid, 'username') + self.user = self.db.user.get(self.userid, 'username') # re-open the database for real, using the user self.opendb(self.user) diff --git a/roundup/roundupdb.py b/roundup/roundupdb.py index e596743..00b6092 100644 --- a/roundup/roundupdb.py +++ b/roundup/roundupdb.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: roundupdb.py,v 1.86 2003-04-27 02:24:37 richard Exp $ +# $Id: roundupdb.py,v 1.87 2003-09-06 07:27:30 jlgijsbers Exp $ __doc__ = """ Extending hyperdb with types specific to issue-tracking. @@ -27,6 +27,8 @@ import base64, quopri, mimetypes from rfc2822 import encode_header +from roundup import password, date + # if available, use the 'email' module, otherwise fallback to 'rfc822' try : from email.Utils import formataddr as straddr @@ -70,6 +72,36 @@ class Database: timezone = 0 return timezone + def confirm_registration(self, otk): + props = self.otks.getall(otk) + for propname, proptype in self.user.getprops().items(): + value = props.get(propname, None) + if value is None: + pass + elif isinstance(proptype, hyperdb.Date): + props[propname] = date.Date(value) + elif isinstance(proptype, hyperdb.Interval): + props[propname] = date.Interval(value) + elif isinstance(proptype, hyperdb.Password): + props[propname] = password.Password() + props[propname].unpack(value) + + # tag new user creation with 'admin' + self.journaltag = 'admin' + self.figure_curuserid() + + # create the new user + cl = self.user + + props['roles'] = self.config.NEW_WEB_USER_ROLES + del props['__time'] + userid = cl.create(**props) + # clear the props from the otk database + self.otks.destroy(otk) + self.commit() + + return userid + class MessageSendError(RuntimeError): pass