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

« back to all changes in this revision

Viewing changes to www/dispatch/__init__.py

  • Committer: chadnickbok
  • Date: 2009-01-13 03:13:59 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:1104
Created a new app, logout, which when given a GET
request opens a new page, with a button asking for
confirmation to logout.

When given a POST request, logs the user out.

Fixes issue #65

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
import socket
51
51
import time
52
52
 
53
 
# List of cookies that IVLE uses (to be removed at logout)
54
 
ivle_cookies = ["ivleforumcookie", "clipboard"]
55
 
 
56
53
def handler(req):
57
54
    """Handles a request which may be to anywhere in the site except media.
58
55
    Intended to be called by mod_python, as a handler.
96
93
    # Check req.app to see if it is valid. 404 if not.
97
94
    if req.app is not None and req.app not in conf.apps.app_url:
98
95
        # Maybe it is a special app!
99
 
        if req.app == 'logout':
100
 
            logout(req)
101
 
        else:
102
 
            req.throw_error(Request.HTTP_NOT_FOUND,
103
 
                "There is no application called %s." % repr(req.app))
 
96
        #if req.app == 'logout':
 
97
        #    logout(req)
 
98
        #else:
 
99
        req.throw_error(Request.HTTP_NOT_FOUND,
 
100
            "There is no application called %s." % repr(req.app))
104
101
 
105
102
    # Special handling for public mode - only allow the public app, call it
106
103
    # and get out.
172
169
    # Use req.throw_error to do that.
173
170
    return req.OK
174
171
 
175
 
def logout(req):
176
 
    """Log out the current user (if any) by destroying the session state.
177
 
    Then redirect to the top-level IVLE page."""
178
 
    session = req.get_session()
179
 
    session.invalidate()
180
 
    session.delete()
181
 
    # Invalidates all IVLE cookies
182
 
    all_cookies = Cookie.get_cookies(req)
183
 
    for cookie in all_cookies:
184
 
        if cookie in ivle_cookies:
185
 
            req.add_cookie(Cookie.Cookie(cookie,'',expires=1,path='/'))
186
 
    req.throw_redirect(util.make_path('')) 
187
 
 
188
172
def handle_unknown_exception(req, exc_type, exc_value, exc_traceback):
189
173
    """
190
174
    Given an exception that has just been thrown from IVLE, print its details