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

« back to all changes in this revision

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

ivle-config now sets appropriate permissions (www-data:, 600) on any config
file that it creates.

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.webapp.security
 
29
import ivle.dispatch.login
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
33
34
 
34
35
class LoginView(XHTMLView):
35
36
    '''A view to allow a user to log in.'''
52
53
        if req.user is not None:
53
54
            req.throw_redirect(nexturl)
54
55
 
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
 
56
        ctx['path'] = ivle.util.make_path('+login') + \
 
57
                         '?' + urllib.urlencode([('url', nexturl)])
62
58
 
63
59
        # If this succeeds, the user is invalid.
64
 
        user = ivle.webapp.security.get_user_details(req)
 
60
        user = get_user_details(req)
65
61
        if user is not None:
66
62
            if user.state == "no_agreement":
67
63
                # Authenticated, but need to accept the ToS. Send them there.
69
65
                # if you are not planning to display a ToS page - the ToS
70
66
                # acceptance process actually calls usrmgt to create the user
71
67
                # jails and related stuff.
72
 
                req.throw_redirect(ivle.util.make_path('+tos') + query_string)
 
68
                req.throw_redirect(ivle.util.make_path('+tos') + \
 
69
                        '?' + urllib.urlencode([('url', nexturl)]))
73
70
            elif user.state == "pending":
74
71
                # FIXME: this isn't quite the right answer, but it
75
72
                # should be more robust in the short term.
83
80
        if req.method == "POST":
84
81
            # While req.user is normally set to get_user_details, it won't set
85
82
            # it if the account isn't valid. So we get it ourselves.
86
 
            user = ivle.webapp.security.get_user_details(req)
 
83
            user = get_user_details(req)
87
84
 
88
85
            badlogin = None
89
86
 
115
112
                        req.store.commit()
116
113
 
117
114
                        # Create cookies for plugins that might request them.
118
 
                        for plugin in req.config.plugin_index[CookiePlugin]:
 
115
                        for plugin in req.plugin_index[CookiePlugin]:
119
116
                            for cookie in plugin.cookies:
120
117
                                # The function can be None if they just need to be
121
118
                                # deleted at logout.
138
135
    def authorize(self, req):
139
136
        # This can be used by any authenticated user, even if they haven't
140
137
        # accepted the ToS yet.
141
 
        return ivle.webapp.security.get_user_details(req) is not None
 
138
        return ivle.dispatch.login.get_user_details(req) is not None
142
139
 
143
140
    def populate(self, req, ctx):
144
141
        if req.method == "POST":