Mercurial > p > roundup > code
comparison roundup/cgi/actions.py @ 2052:78e6a1e4984e
forward-port from maint branch
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Wed, 25 Feb 2004 23:27:54 +0000 |
| parents | d124af927369 |
| children | 0eeecaac008a |
comparison
equal
deleted
inserted
replaced
| 2049:5a5f66e6b0e1 | 2052:78e6a1e4984e |
|---|---|
| 1 import re, cgi, StringIO, urllib, Cookie, time, random | 1 import re, cgi, StringIO, urllib, Cookie, time, random |
| 2 | 2 |
| 3 from roundup import hyperdb, token, date, password, rcsv | 3 from roundup import hyperdb, token, date, password, rcsv |
| 4 from roundup.i18n import _ | 4 from roundup.i18n import _ |
| 5 from roundup.cgi import templating | 5 from roundup.cgi import templating |
| 6 from roundup.cgi.exceptions import Redirect, Unauthorised | 6 from roundup.cgi.exceptions import Redirect, Unauthorised, SeriousError |
| 7 from roundup.mailgw import uidFromAddress | 7 from roundup.mailgw import uidFromAddress |
| 8 | 8 |
| 9 __all__ = ['Action', 'ShowAction', 'RetireAction', 'SearchAction', | 9 __all__ = ['Action', 'ShowAction', 'RetireAction', 'SearchAction', |
| 10 'EditCSVAction', 'EditItemAction', 'PassResetAction', | 10 'EditCSVAction', 'EditItemAction', 'PassResetAction', |
| 11 'ConfRegoAction', 'RegisterAction', 'LoginAction', 'LogoutAction', | 11 'ConfRegoAction', 'RegisterAction', 'LoginAction', 'LogoutAction', |
| 64 if typere.match(key): | 64 if typere.match(key): |
| 65 t = self.form[key].value.strip() | 65 t = self.form[key].value.strip() |
| 66 elif numre.match(key): | 66 elif numre.match(key): |
| 67 n = self.form[key].value.strip() | 67 n = self.form[key].value.strip() |
| 68 if not t: | 68 if not t: |
| 69 raise ValueError, 'Invalid %s number'%t | 69 raise ValueError, 'No type specified' |
| 70 if not n: | |
| 71 raise SeriousError, _('No ID entered') | |
| 72 try: | |
| 73 int(n) | |
| 74 except ValueError: | |
| 75 d = {'input': n, 'classname': t} | |
| 76 raise SeriousError, _( | |
| 77 '"%(input)s" is not an ID (%(classname)s ID required)')%d | |
| 70 url = '%s%s%s'%(self.db.config.TRACKER_WEB, t, n) | 78 url = '%s%s%s'%(self.db.config.TRACKER_WEB, t, n) |
| 71 raise Redirect, url | 79 raise Redirect, url |
| 72 | 80 |
| 73 class RetireAction(Action): | 81 class RetireAction(Action): |
| 74 name = 'retire' | 82 name = 'retire' |
| 591 'or address') | 599 'or address') |
| 592 return | 600 return |
| 593 | 601 |
| 594 # generate the one-time-key and store the props for later | 602 # generate the one-time-key and store the props for later |
| 595 otk = ''.join([random.choice(chars) for x in range(32)]) | 603 otk = ''.join([random.choice(chars) for x in range(32)]) |
| 596 self.db.otks.set(otk, uid=uid, __time=time.time()) | 604 d = {'uid': uid, self.db.otks.timestamp: time.time()} |
| 605 self.db.otks.set(otk, **d) | |
| 597 | 606 |
| 598 # send the email | 607 # send the email |
| 599 tracker_name = self.db.config.TRACKER_NAME | 608 tracker_name = self.db.config.TRACKER_NAME |
| 600 subject = 'Confirm reset of password for %s'%tracker_name | 609 subject = 'Confirm reset of password for %s'%tracker_name |
| 601 body = ''' | 610 body = ''' |
| 656 """Attempt to create a new user based on the contents of the form | 665 """Attempt to create a new user based on the contents of the form |
| 657 and then set the cookie. | 666 and then set the cookie. |
| 658 | 667 |
| 659 Return 1 on successful login. | 668 Return 1 on successful login. |
| 660 """ | 669 """ |
| 661 props = self.client.parsePropsFromForm(create=1)[0][('user', None)] | 670 props = self.client.parsePropsFromForm(create=True)[0][('user', None)] |
| 662 | 671 |
| 663 # registration isn't allowed to supply roles | 672 # registration isn't allowed to supply roles |
| 664 if props.has_key('roles'): | 673 if props.has_key('roles'): |
| 665 raise Unauthorised, _("It is not permitted to supply roles " | 674 raise Unauthorised, _("It is not permitted to supply roles " |
| 666 "at registration.") | 675 "at registration.") |
| 684 props[propname] = str(value) | 693 props[propname] = str(value) |
| 685 elif isinstance(proptype, hyperdb.Interval): | 694 elif isinstance(proptype, hyperdb.Interval): |
| 686 props[propname] = str(value) | 695 props[propname] = str(value) |
| 687 elif isinstance(proptype, hyperdb.Password): | 696 elif isinstance(proptype, hyperdb.Password): |
| 688 props[propname] = str(value) | 697 props[propname] = str(value) |
| 689 props['__time'] = time.time() | 698 props[self.db.otks.timestamp] = time.time() |
| 690 self.db.otks.set(otk, **props) | 699 self.db.otks.set(otk, **props) |
| 691 | 700 |
| 692 # send the email | 701 # send the email |
| 693 tracker_name = self.db.config.TRACKER_NAME | 702 tracker_name = self.db.config.TRACKER_NAME |
| 694 tracker_email = self.db.config.TRACKER_EMAIL | 703 tracker_email = self.db.config.TRACKER_EMAIL |
