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

« back to all changes in this revision

Viewing changes to www/dispatch/__init__.py

  • Committer: drtomc
  • Date: 2007-12-21 00:20:24 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:111
Checkpoint work on the console.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
 
38
38
from request import Request
39
39
import html
40
 
import login
41
40
from common import util
42
41
 
43
42
def handler(req):
52
51
 
53
52
    # Check req.app to see if it is valid. 404 if not.
54
53
    if req.app is not None and req.app not in conf.apps.app_url:
55
 
        # Maybe it is a special app!
56
 
        if req.app == 'logout':
57
 
            logout(req)
58
 
        else:
59
 
            # TODO: Nicer 404 message?
60
 
            req.throw_error(Request.HTTP_NOT_FOUND)
61
 
 
62
 
    # Special handling for public mode - just call public app and get out
63
 
    # NOTE: This will not behave correctly if the public app uses
64
 
    # write_html_head_foot, but "serve" does not.
65
 
    if req.publicmode:
66
 
        app = conf.apps.app_url[conf.apps.public_app]
67
 
        apps.call_app(app.dir, req)
68
 
        return req.OK
 
54
        # TODO: Nicer 404 message?
 
55
        req.throw_error(Request.HTTP_NOT_FOUND)
69
56
 
70
57
    # app is the App object for the chosen app
71
58
    if req.app is None:
72
 
        app = conf.apps.app_url[conf.apps.default_app]
 
59
        app = conf.apps.app_url[conf.default_app]
73
60
    else:
74
61
        app = conf.apps.app_url[req.app]
75
62
 
76
63
    # Check if app requires auth. If so, perform authentication and login.
77
64
    if app.requireauth:
78
 
        req.username = login.login(req)
79
 
        logged_in = req.username is not None
 
65
        # TODO: Perform authentication
 
66
        pass
 
67
 
 
68
    # If user did not specify an app, HTTP redirect to default app and exit.
 
69
    if req.app is None:
 
70
        req.throw_redirect(util.make_path(conf.default_app))
 
71
 
 
72
    # Set the default title to the app's tab name, if any. Otherwise URL name.
 
73
    if app.name is not None:
 
74
        req.title = app.name
80
75
    else:
81
 
        req.username = login.get_username(req)
82
 
        logged_in = True
83
 
 
84
 
    if logged_in:
85
 
        # Keep the user's session alive by writing to the session object.
86
 
        req.get_session().save()
87
 
        # If user did not specify an app, HTTP redirect to default app and
88
 
        # exit.
89
 
        if req.app is None:
90
 
            req.throw_redirect(util.make_path(conf.apps.default_app))
91
 
 
92
 
        # Set the default title to the app's tab name, if any. Otherwise URL
93
 
        # name.
94
 
        if app.name is not None:
95
 
            req.title = app.name
96
 
        else:
97
 
            req.title = req.app
98
 
 
99
 
        # Call the specified app with the request object
100
 
        apps.call_app(app.dir, req)
101
 
    # if not logged in, login.login will have written the login box.
102
 
    # Just clean up and exit.
 
76
        req.title = req.app
 
77
 
 
78
    # Call the specified app with the request object
 
79
    apps.call_app(app.dir, req)
103
80
 
104
81
    # MAKE SURE we write the HTTP (and possibly HTML) header. This
105
82
    # wouldn't happen if nothing else ever got written, so we have to make
110
87
    if req.write_html_head_foot:
111
88
        html.write_html_foot(req)
112
89
 
113
 
    # Note: Apache will not write custom HTML error messages here.
114
 
    # Use req.throw_error to do that.
115
 
    return req.OK
 
90
    # Have Apache output its own HTML code if non-200 status codes were found
 
91
    return req.status
116
92
 
117
 
def logout(req):
118
 
    """Log out the current user (if any) by destroying the session state.
119
 
    Then redirect to the top-level IVLE page."""
120
 
    session = req.get_session()
121
 
    session.invalidate()
122
 
    session.delete()
123
 
    req.throw_redirect(util.make_path(''))