~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-02-27 05:07:09 UTC
  • Revision ID: grantw@unimelb.edu.au-20090227050709-k16kvhyl50nzjbwm
Subject URLs now contain the short name (eg. info1) rather than the code
(eg. 600151).

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.dispatch.login
 
29
import ivle.webapp.security
30
30
from ivle.auth import authenticate, AuthError
31
31
from ivle.webapp.base.xhtml import XHTMLView
32
32
from ivle.webapp.base.plugins import CookiePlugin
33
 
from ivle.dispatch.login import get_user_details
34
33
 
35
34
class LoginView(XHTMLView):
36
35
    '''A view to allow a user to log in.'''
53
52
        if req.user is not None:
54
53
            req.throw_redirect(nexturl)
55
54
 
56
 
        ctx['path'] = ivle.util.make_path('+login') + \
57
 
                         '?' + urllib.urlencode([('url', nexturl)])
 
55
        # Don't give any URL if we want /.
 
56
        if nexturl == '/':
 
57
            query_string = ''
 
58
        else:
 
59
            query_string = '?url=' + urllib.quote(nexturl, safe="/~")
 
60
 
 
61
        ctx['path'] = ivle.util.make_path('+login') + query_string
58
62
 
59
63
        # If this succeeds, the user is invalid.
60
 
        user = get_user_details(req)
 
64
        user = ivle.webapp.security.get_user_details(req)
61
65
        if user is not None:
62
66
            if user.state == "no_agreement":
63
67
                # Authenticated, but need to accept the ToS. Send them there.
65
69
                # if you are not planning to display a ToS page - the ToS
66
70
                # acceptance process actually calls usrmgt to create the user
67
71
                # jails and related stuff.
68
 
                req.throw_redirect(ivle.util.make_path('+tos') + \
69
 
                        '?' + urllib.urlencode([('url', nexturl)]))
 
72
                req.throw_redirect(ivle.util.make_path('+tos') + query_string)
70
73
            elif user.state == "pending":
71
74
                # FIXME: this isn't quite the right answer, but it
72
75
                # should be more robust in the short term.
80
83
        if req.method == "POST":
81
84
            # While req.user is normally set to get_user_details, it won't set
82
85
            # it if the account isn't valid. So we get it ourselves.
83
 
            user = get_user_details(req)
 
86
            user = ivle.webapp.security.get_user_details(req)
84
87
 
85
88
            badlogin = None
86
89
 
108
111
                        session = req.get_session()
109
112
                        session['login'] = user.login
110
113
                        session.save()
 
114
                        session.unlock()
111
115
                        user.last_login = datetime.datetime.now()
112
116
                        req.store.commit()
113
117
 
135
139
    def authorize(self, req):
136
140
        # This can be used by any authenticated user, even if they haven't
137
141
        # accepted the ToS yet.
138
 
        return ivle.dispatch.login.get_user_details(req) is not None
 
142
        return ivle.webapp.security.get_user_details(req) is not None
139
143
 
140
144
    def populate(self, req, ctx):
141
145
        if req.method == "POST":