~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to www/dispatch/request.py

  • Committer: mattgiuca
  • Date: 2007-12-21 06:15:19 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:124
dispatch/request: Added new fields: method and username.
                  Added new methods: get_session and get_fieldstorage.
dispatch/html: Writes out username of logged in user, and a "logout" link.
dispatch/__init__: Handles special logout app.
                   Performs authentication, and stores username in req.
                   No longer lets apache print HTML errors. Just returns OK.
dispatch: Added login module.

Added new package: auth (handles authentication and authorization).
    Currently just does hard-coded dummy authentication.

debuginfo: Added new info for new fields of request, and also prints out
        fieldstorage and session information.

conf/apps.py: debuginfo does not require auth (careful!)
              Commented out debuginfo (no longer displays warning)

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
import common.util
27
27
import mod_python
 
28
from mod_python import (util, Session)
28
29
 
29
30
class Request:
30
31
    """An IVLE request object. This is presented to the IVLE apps as a way of
31
32
    interacting with the web server and the dispatcher.
32
33
 
33
34
    Request object attributes:
 
35
        method (read)
 
36
            String. The request method (eg. 'GET', 'POST', etc)
34
37
        uri (read)
35
38
            String. The path portion of the URI.
36
39
        app (read)
39
42
            String. The path specified in the URL *not including* the
40
43
            application or the IVLE location prefix. eg. a URL of
41
44
            "/ivle/files/joe/myfiles" has a path of "joe/myfiles".
 
45
        username (read)
 
46
            String. Login name of the user who is currently logged in, or
 
47
            None.
42
48
 
43
49
        status (write)
44
50
            Int. Response status number. Use one of the status codes defined
137
143
        self.headers_written = False
138
144
 
139
145
        # Inherit values for the input members
 
146
        self.method = req.method
140
147
        self.uri = req.uri
141
148
        # Split the given path into the app (top-level dir) and sub-path
142
149
        # (after first stripping away the root directory)
143
150
        (self.app, self.path) = (
144
151
            common.util.split_path(common.util.unmake_path(req.uri)))
 
152
        self.username = None
145
153
 
146
154
        # Default values for the output members
147
155
        self.status = Request.OK
215
223
        Request class.
216
224
        """
217
225
        mod_python.util.redirect(self.apache_req, location)
 
226
 
 
227
    def get_session(self):
 
228
        """Returns a mod_python Session object for this request.
 
229
        Note that this is dependent on mod_python and may need to change
 
230
        interface if porting away from mod_python."""
 
231
        # Cache the session object
 
232
        if not hasattr(self, 'session'):
 
233
            self.session = Session.Session(self.apache_req)
 
234
        return self.session
 
235
 
 
236
    def get_fieldstorage(self):
 
237
        """Returns a mod_python FieldStorage object for this request.
 
238
        Note that this is dependent on mod_python and may need to change
 
239
        interface if porting away from mod_python."""
 
240
        # Cache the fieldstorage object
 
241
        if not hasattr(self, 'fields'):
 
242
            self.fields = util.FieldStorage(self.apache_req)
 
243
        return self.fields