~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: 2010-02-25 07:34:50 UTC
  • Revision ID: grantw@unimelb.edu.au-20100225073450-zcl8ev5hlyhbszeu
Activate the Storm C extensions if possible. Moar speed.

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
43
43
        fields = req.get_fieldstorage()
44
44
        nexturl = fields.getfirst('url')
45
45
 
 
46
        # XXX Warning that Internet Explorer is unsupported
 
47
        # Test if the user is in Internet Explorer
 
48
        try:
 
49
            useragent = req.headers_in['User-Agent']
 
50
            # A bit of very basic UA string detection
 
51
            ctx['msie'] = ('MSIE' in useragent
 
52
                           and 'AppleWebKit' not in useragent
 
53
                           and 'Gecko' not in useragent
 
54
                           and 'Opera' not in useragent)
 
55
        except KeyError:
 
56
            ctx['msie'] = False
 
57
 
46
58
        if nexturl is None:
47
59
            nexturl = '/'
48
60
 
49
 
        # We are already logged in. Don't bother logging in again.
 
61
        # We are already logged in. If it is a POST, they might be trying to
 
62
        # clobber their session with some new credentials. That's their own
 
63
        # business, so we let them do it. Otherwise, we don't bother prompting
 
64
        # and just redirect to the destination.
50
65
        # 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:
 
66
        # invalid (state != enabled, or expired).
 
67
        if req.method != "POST" and req.user is not None:
53
68
            req.throw_redirect(nexturl)
54
69
 
55
70
        # Don't give any URL if we want /.
58
73
        else:
59
74
            query_string = '?url=' + urllib.quote(nexturl, safe="/~")
60
75
 
61
 
        ctx['path'] = ivle.util.make_path('+login') + query_string
 
76
        ctx['path'] = req.make_path('+login') + query_string
62
77
 
63
78
        # If this succeeds, the user is invalid.
64
79
        user = ivle.webapp.security.get_user_details(req)
69
84
                # if you are not planning to display a ToS page - the ToS
70
85
                # acceptance process actually calls usrmgt to create the user
71
86
                # jails and related stuff.
72
 
                req.throw_redirect(ivle.util.make_path('+tos') + query_string)
 
87
                req.throw_redirect(req.make_path('+tos') + query_string)
73
88
            elif user.state == "pending":
74
89
                # FIXME: this isn't quite the right answer, but it
75
90
                # should be more robust in the short term.
98
113
                else:
99
114
                    user = None
100
115
                    try:
101
 
                        user = authenticate.authenticate(req.store,
102
 
                                    username.value, password.value)
 
116
                        # Username is case insensitive
 
117
                        user = authenticate.authenticate(req.config, req.store,
 
118
                                    username.value.lower(), password.value)
103
119
                    except AuthError, msg:
104
120
                        badlogin = msg
105
121
                    if user is None:
111
127
                        session = req.get_session()
112
128
                        session['login'] = user.login
113
129
                        session.save()
 
130
                        session.unlock()
114
131
                        user.last_login = datetime.datetime.now()
115
 
                        req.store.commit()
116
132
 
117
133
                        # Create cookies for plugins that might request them.
118
134
                        for plugin in req.config.plugin_index[CookiePlugin]:
123
139
                                    req.add_cookie(mod_python.Cookie.Cookie(cookie,
124
140
                                          plugin.cookies[cookie](user), path='/'))
125
141
 
 
142
                        # Add any new enrolments.
 
143
                        ivle.pulldown_subj.enrol_user(req.config, req.store, user)
 
144
                        req.store.commit()
 
145
 
126
146
                        req.throw_redirect(nexturl)
127
147
 
128
148
                # We didn't succeed.
144
164
        if req.method == "POST":
145
165
            req.logout()
146
166
        else:
147
 
            ctx['path'] =  ivle.util.make_path('+logout')
 
167
            ctx['path'] =  req.make_path('+logout')