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

« back to all changes in this revision

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

Drop www/ stuff from setup.

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.pulldown_subj
 
28
import ivle.util
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. 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.
 
49
        # We are already logged in. Don't bother logging in again.
53
50
        # Note that req.user is None even if we are 'logged in', if the user is
54
 
        # invalid (state != enabled, or expired).
55
 
        if req.method != "POST" and req.user is not None:
 
51
        # invalid.
 
52
        if req.user is not None:
56
53
            req.throw_redirect(nexturl)
57
54
 
58
 
        # Don't give any URL if we want /.
59
 
        if nexturl == '/':
60
 
            query_string = ''
61
 
        else:
62
 
            query_string = '?url=' + urllib.quote(nexturl, safe="/~")
63
 
 
64
 
        ctx['path'] = req.make_path('+login') + query_string
 
55
        ctx['path'] = ivle.util.make_path('+login') + \
 
56
                         '?' + urllib.urlencode([('url', nexturl)])
65
57
 
66
58
        # If this succeeds, the user is invalid.
67
59
        user = ivle.webapp.security.get_user_details(req)
72
64
                # if you are not planning to display a ToS page - the ToS
73
65
                # acceptance process actually calls usrmgt to create the user
74
66
                # jails and related stuff.
75
 
                req.throw_redirect(req.make_path('+tos') + query_string)
 
67
                req.throw_redirect(ivle.util.make_path('+tos') + \
 
68
                        '?' + urllib.urlencode([('url', nexturl)]))
76
69
            elif user.state == "pending":
77
70
                # FIXME: this isn't quite the right answer, but it
78
71
                # should be more robust in the short term.
101
94
                else:
102
95
                    user = None
103
96
                    try:
104
 
                        user = authenticate.authenticate(req.config, req.store,
 
97
                        user = authenticate.authenticate(req.store,
105
98
                                    username.value, password.value)
106
99
                    except AuthError, msg:
107
100
                        badlogin = msg
114
107
                        session = req.get_session()
115
108
                        session['login'] = user.login
116
109
                        session.save()
117
 
                        session.unlock()
118
110
                        user.last_login = datetime.datetime.now()
 
111
                        req.store.commit()
119
112
 
120
113
                        # Create cookies for plugins that might request them.
121
114
                        for plugin in req.config.plugin_index[CookiePlugin]:
126
119
                                    req.add_cookie(mod_python.Cookie.Cookie(cookie,
127
120
                                          plugin.cookies[cookie](user), path='/'))
128
121
 
129
 
                        # Add any new enrolments.
130
 
                        ivle.pulldown_subj.enrol_user(req.config, req.store, user)
131
 
                        req.store.commit()
132
 
 
133
122
                        req.throw_redirect(nexturl)
134
123
 
135
124
                # We didn't succeed.
151
140
        if req.method == "POST":
152
141
            req.logout()
153
142
        else:
154
 
            ctx['path'] =  req.make_path('+logout')
 
143
            ctx['path'] =  ivle.util.make_path('+logout')