1- #$Id: actions.py,v 1.37 2004-08-07 22:17:11 richard Exp $
1+ #$Id: actions.py,v 1.38 2004-11-18 15:58:23 a1s Exp $
22
33import re , cgi , StringIO , urllib , Cookie , time , random
44
55from roundup import hyperdb , token , date , password , rcsv , exceptions
66from roundup .i18n import _
7- from roundup .cgi import templating
8- from roundup .cgi .exceptions import Redirect , Unauthorised , SeriousError
7+ from roundup .cgi import exceptions , templating
98from roundup .mailgw import uidFromAddress
109
1110__all__ = ['Action' , 'ShowAction' , 'RetireAction' , 'SearchAction' ,
@@ -50,7 +49,8 @@ def permission(self):
5049 if (self .permissionType and
5150 not self .hasPermission (self .permissionType )):
5251 info = {'action' : self .name , 'classname' : self .classname }
53- raise Unauthorised , self ._ ('You do not have permission to '
52+ raise exceptions .Unauthorised , self ._ (
53+ 'You do not have permission to '
5454 '%(action)s the %(classname)s class.' )% info
5555
5656 _marker = []
@@ -80,15 +80,15 @@ def handle(self, typere=re.compile('[@:]type'),
8080 if not t :
8181 raise ValueError , self ._ ('No type specified' )
8282 if not n :
83- raise SeriousError , self ._ ('No ID entered' )
83+ raise exceptions . SeriousError , self ._ ('No ID entered' )
8484 try :
8585 int (n )
8686 except ValueError :
8787 d = {'input' : n , 'classname' : t }
88- raise SeriousError , self ._ (
88+ raise exceptions . SeriousError , self ._ (
8989 '"%(input)s" is not an ID (%(classname)s ID required)' )% d
9090 url = '%s%s%s' % (self .base , t , n )
91- raise Redirect , url
91+ raise exceptions . Redirect , url
9292
9393class RetireAction (Action ):
9494 name = 'retire'
@@ -420,7 +420,7 @@ def _changenode(self, cn, nodeid, props):
420420 """Change the node based on the contents of the form."""
421421 # check for permission
422422 if not self .editItemPermission (props ):
423- raise Unauthorised , self ._ (
423+ raise exceptions . Unauthorised , self ._ (
424424 'You do not have permission to edit %(class)s'
425425 ) % {'class' : cn }
426426
@@ -432,7 +432,7 @@ def _createnode(self, cn, props):
432432 """Create a node based on the contents of the form."""
433433 # check for permission
434434 if not self .newItemPermission (props ):
435- raise Unauthorised , self ._ (
435+ raise exceptions . Unauthorised , self ._ (
436436 'You do not have permission to create %(class)s'
437437 ) % {'class' : cn }
438438
@@ -455,7 +455,7 @@ def editItemPermission(self, props):
455455 """
456456 if self .classname == 'user' :
457457 if props .has_key ('roles' ) and not self .hasPermission ('Web Roles' ):
458- raise Unauthorised , self ._ (
458+ raise exceptions . Unauthorised , self ._ (
459459 "You do not have permission to edit user roles" )
460460 if self .isEditingSelf ():
461461 return 1
@@ -533,7 +533,7 @@ def handle(self):
533533 if self .nodeid is None :
534534 req = templating .HTMLRequest (self .client )
535535 url += '&' + req .indexargs_href ('' , {})[1 :]
536- raise Redirect , url
536+ raise exceptions . Redirect , url
537537
538538class NewItemAction (EditCommon , Action ):
539539 def handle (self ):
@@ -563,8 +563,8 @@ def handle(self):
563563 self .db .commit ()
564564
565565 # redirect to the new item's page
566- raise Redirect , '%s%s%s?@ok_message=%s&@template=%s' % ( self . base ,
567- self .classname , self .nodeid , urllib .quote (messages ),
566+ raise exceptions . Redirect , '%s%s%s?@ok_message=%s&@template=%s' % (
567+ self .base , self . classname , self .nodeid , urllib .quote (messages ),
568568 urllib .quote (self .template ))
569569
570570class PassResetAction (Action ):
@@ -734,7 +734,7 @@ def handle(self):
734734 # registration isn't allowed to supply roles
735735 user_props = props [('user' , None )]
736736 if user_props .has_key ('roles' ):
737- raise Unauthorised , self ._ (
737+ raise exceptions . Unauthorised , self ._ (
738738 "It is not permitted to supply roles at registration." )
739739
740740 # skip the confirmation step?
@@ -802,7 +802,7 @@ def handle(self):
802802 self .db .commit ()
803803
804804 # redirect to the "you're almost there" page
805- raise Redirect , '%suser?@template=rego_progress' % self .base
805+ raise exceptions . Redirect , '%suser?@template=rego_progress' % self .base
806806
807807class LogoutAction (Action ):
808808 def handle (self ):
@@ -838,34 +838,35 @@ def handle(self):
838838 else :
839839 password = ''
840840
841- # make sure the user exists
842841 try :
843- self .client .userid = self .db .user .lookup (self .client .user )
844- except KeyError :
845- name = self .client .user
846- self .client .error_message .append (self ._ ('Ivalid login' ))
842+ self .verifyLogin (self .client .user , password )
843+ except exceptions .LoginError , err :
847844 self .client .make_user_anonymous ()
845+ self .client .error_message .extend (list (err .args ))
848846 return
849847
848+ # now we're OK, re-open the database for real, using the user
849+ self .client .opendb (self .client .user )
850+
851+ # set the session cookie
852+ self .client .set_cookie (self .client .user )
853+
854+ def verifyLogin (self , username , password ):
855+ # make sure the user exists
856+ try :
857+ self .client .userid = self .db .user .lookup (username )
858+ except KeyError :
859+ raise exceptions .LoginError , self ._ ('Invalid login' )
860+
850861 # verify the password
851862 if not self .verifyPassword (self .client .userid , password ):
852- self .client .make_user_anonymous ()
853- self .client .error_message .append (self ._ ('Invalid login' ))
854- return
863+ raise exceptions .LoginError , self ._ ('Invalid login' )
855864
856865 # Determine whether the user has permission to log in.
857866 # Base behaviour is to check the user has "Web Access".
858867 if not self .hasPermission ("Web Access" ):
859- self .client .make_user_anonymous ()
860- self .client .error_message .append (
861- self ._ ("You do not have permission to login" ))
862- return
863-
864- # now we're OK, re-open the database for real, using the user
865- self .client .opendb (self .client .user )
866-
867- # set the session cookie
868- self .client .set_cookie (self .client .user )
868+ raise exceptions .LoginError , self ._ (
869+ "You do not have permission to login" )
869870
870871 def verifyPassword (self , userid , password ):
871872 ''' Verify the password that the user has supplied
0 commit comments