1- # $Id: client.py,v 1.17 2002-09-06 03:21:30 richard Exp $
1+ # $Id: client.py,v 1.18 2002-09-06 05:53:02 richard Exp $
22
33__doc__ = """
44WWW request handler (also used in the stand-alone server).
@@ -350,7 +350,7 @@ def content(self):
350350 'editCSV' : 'editCSVAction' ,
351351 'new' : 'newItemAction' ,
352352 'register' : 'registerAction' ,
353- 'login' : 'login_action ' ,
353+ 'login' : 'loginAction ' ,
354354 'logout' : 'logout_action' ,
355355 'search' : 'searchAction' ,
356356 }
@@ -363,7 +363,7 @@ def handle_action(self):
363363 "edit" -> self.editItemAction
364364 "new" -> self.newItemAction
365365 "register" -> self.registerAction
366- "login" -> self.login_action
366+ "login" -> self.loginAction
367367 "logout" -> self.logout_action
368368 "search" -> self.searchAction
369369
@@ -380,6 +380,8 @@ def handle_action(self):
380380 getattr (self , self .actions [action ])()
381381 except Redirect :
382382 raise
383+ except Unauthorised :
384+ raise
383385 except :
384386 self .db .rollback ()
385387 s = StringIO .StringIO ()
@@ -465,8 +467,11 @@ def opendb(self, user):
465467 #
466468 # Actions
467469 #
468- def login_action (self ):
469- ''' Attempt to log a user in and set the cookie
470+ def loginAction (self ):
471+ ''' Attempt to log a user in.
472+
473+ Sets up a session for the user which contains the login
474+ credentials.
470475 '''
471476 # we need the username at a minimum
472477 if not self .form .has_key ('__login_name' ):
@@ -496,11 +501,23 @@ def login_action(self):
496501 self .error_message .append (_ ('Incorrect password' ))
497502 return
498503
499- # XXX check for web access permission!!!!
504+ # make sure we're allowed to be here
505+ if not self .loginPermission ():
506+ self .make_user_anonymous ()
507+ raise Unauthorised , _ ("You do not have permission to login" )
500508
501509 # set the session cookie
502510 self .set_cookie (self .user , password )
503511
512+ def loginPermission (self ):
513+ ''' Determine whether the user has permission to log in.
514+
515+ Base behaviour is to check the user has "Web Access".
516+ '''
517+ if not self .db .security .hasPermission ('Web Access' , self .userid ):
518+ return 0
519+ return 1
520+
504521 def logout_action (self ):
505522 ''' Make us really anonymous - nuke the cookie too
506523 '''
@@ -876,7 +893,6 @@ def searchAction(self):
876893 # commit the query change to the database
877894 self .db .commit ()
878895
879-
880896 def searchPermission (self ):
881897 ''' Determine whether the user has permission to search this class.
882898
@@ -1052,6 +1068,7 @@ def parsePropsFromForm(db, cl, form, nodeid=0, num_re=re.compile('^\d+$')):
10521068 must be supplied or a ValueError will be raised.
10531069 '''
10541070 required = []
1071+ print form .keys ()
10551072 if form .has_key (':required' ):
10561073 value = form [':required' ]
10571074 print 'required' , value
@@ -1139,6 +1156,10 @@ def parsePropsFromForm(db, cl, form, nodeid=0, num_re=re.compile('^\d+$')):
11391156 elif isinstance (proptype , hyperdb .Number ):
11401157 props [key ] = value = int (value )
11411158
1159+ # register this as received if required
1160+ if key in required :
1161+ required .remove (key )
1162+
11421163 # get the old value
11431164 if nodeid :
11441165 try :
@@ -1155,12 +1176,9 @@ def parsePropsFromForm(db, cl, form, nodeid=0, num_re=re.compile('^\d+$')):
11551176 props [key ] = value
11561177
11571178 # see if all the required properties have been supplied
1158- l = []
1159- for property in required :
1160- if not props .has_key (property ):
1161- l .append (property )
1162- if l :
1163- raise ValueError , 'Required properties %s not supplied' % (', ' .join (l ))
1179+ if required :
1180+ raise ValueError , 'Required properties %s not supplied' % (
1181+ ', ' .join (required ))
11641182
11651183 return props
11661184
0 commit comments