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

« back to all changes in this revision

Viewing changes to ivle/webapp/security/views.py

  • Committer: William Grant
  • Date: 2009-04-28 08:35:40 UTC
  • Revision ID: grantw@unimelb.edu.au-20090428083540-0mjpvly46rbt8o8l
Drop another unneeded ivle.conf import, from ivle.webapp.help.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
    # This needs to be importable from outside Apache.
26
26
    pass
27
27
 
28
 
import ivle.util
 
28
import ivle.pulldown_subj
29
29
import ivle.webapp.security
30
30
from ivle.auth import authenticate, AuthError
31
31
from ivle.webapp.base.xhtml import XHTMLView
46
46
        if nexturl is None:
47
47
            nexturl = '/'
48
48
 
49
 
        # We are already logged in. Don't bother logging in again.
 
49
        # We are already logged in. If it is a POST, they might be trying to
 
50
        # clobber their session with some new credentials. That's their own
 
51
        # business, so we let them do it. Otherwise, we don't bother prompting
 
52
        # and just redirect to the destination.
50
53
        # Note that req.user is None even if we are 'logged in', if the user is
51
 
        # invalid.
52
 
        if req.user is not None:
 
54
        # invalid (state != enabled, or expired).
 
55
        if req.method != "POST" and req.user is not None:
53
56
            req.throw_redirect(nexturl)
54
57
 
55
58
        # Don't give any URL if we want /.
58
61
        else:
59
62
            query_string = '?url=' + urllib.quote(nexturl, safe="/~")
60
63
 
61
 
        ctx['path'] = ivle.util.make_path('+login') + query_string
 
64
        ctx['path'] = req.make_path('+login') + query_string
62
65
 
63
66
        # If this succeeds, the user is invalid.
64
67
        user = ivle.webapp.security.get_user_details(req)
69
72
                # if you are not planning to display a ToS page - the ToS
70
73
                # acceptance process actually calls usrmgt to create the user
71
74
                # jails and related stuff.
72
 
                req.throw_redirect(ivle.util.make_path('+tos') + query_string)
 
75
                req.throw_redirect(req.make_path('+tos') + query_string)
73
76
            elif user.state == "pending":
74
77
                # FIXME: this isn't quite the right answer, but it
75
78
                # should be more robust in the short term.
111
114
                        session = req.get_session()
112
115
                        session['login'] = user.login
113
116
                        session.save()
 
117
                        session.unlock()
114
118
                        user.last_login = datetime.datetime.now()
115
 
                        req.store.commit()
116
119
 
117
120
                        # Create cookies for plugins that might request them.
118
121
                        for plugin in req.config.plugin_index[CookiePlugin]:
123
126
                                    req.add_cookie(mod_python.Cookie.Cookie(cookie,
124
127
                                          plugin.cookies[cookie](user), path='/'))
125
128
 
 
129
                        # Add any new enrolments.
 
130
                        ivle.pulldown_subj.enrol_user(req.store, user)
 
131
                        req.store.commit()
 
132
 
126
133
                        req.throw_redirect(nexturl)
127
134
 
128
135
                # We didn't succeed.
144
151
        if req.method == "POST":
145
152
            req.logout()
146
153
        else:
147
 
            ctx['path'] =  ivle.util.make_path('+logout')
 
154
            ctx['path'] =  req.make_path('+logout')