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

« back to all changes in this revision

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

ivle-config now allows a blank port to be specified.

In that case, 5432 (the PostgreSQL default) is used.

Show diffs side-by-side

added added

removed removed

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