~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-07-27 10:25:59 UTC
  • Revision ID: grantw@unimelb.edu.au-20100727102559-cvt3fhlaiaknd5bp
Validate uniqueness of Subject.code at the form layer, so we don't crash due to DB constraints.

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
29
28
import ivle.pulldown_subj
30
29
import ivle.webapp.security
31
30
from ivle.auth import authenticate, AuthError
44
43
        fields = req.get_fieldstorage()
45
44
        nexturl = fields.getfirst('url')
46
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
 
47
58
        if nexturl is None:
48
59
            nexturl = '/'
49
60
 
62
73
        else:
63
74
            query_string = '?url=' + urllib.quote(nexturl, safe="/~")
64
75
 
65
 
        ctx['path'] = ivle.util.make_path('+login') + query_string
 
76
        ctx['path'] = req.make_path('+login') + query_string
66
77
 
67
78
        # If this succeeds, the user is invalid.
68
79
        user = ivle.webapp.security.get_user_details(req)
73
84
                # if you are not planning to display a ToS page - the ToS
74
85
                # acceptance process actually calls usrmgt to create the user
75
86
                # jails and related stuff.
76
 
                req.throw_redirect(ivle.util.make_path('+tos') + query_string)
 
87
                req.throw_redirect(req.make_path('+tos') + query_string)
77
88
            elif user.state == "pending":
78
89
                # FIXME: this isn't quite the right answer, but it
79
90
                # should be more robust in the short term.
102
113
                else:
103
114
                    user = None
104
115
                    try:
105
 
                        user = authenticate.authenticate(req.store,
106
 
                                    username.value, password.value)
 
116
                        # Username is case insensitive
 
117
                        user = authenticate.authenticate(req.config, req.store,
 
118
                                    username.value.lower(), password.value)
107
119
                    except AuthError, msg:
108
120
                        badlogin = msg
109
121
                    if user is None:
128
140
                                          plugin.cookies[cookie](user), path='/'))
129
141
 
130
142
                        # Add any new enrolments.
131
 
                        ivle.pulldown_subj.enrol_user(req.store, user)
 
143
                        ivle.pulldown_subj.enrol_user(req.config, req.store, user)
132
144
                        req.store.commit()
133
145
 
134
146
                        req.throw_redirect(nexturl)
152
164
        if req.method == "POST":
153
165
            req.logout()
154
166
        else:
155
 
            ctx['path'] =  ivle.util.make_path('+logout')
 
167
            ctx['path'] =  req.make_path('+logout')