154
154
from ivle.auth import AuthError, authenticate
157
from ivle.webapp.base.views import BaseView
158
from ivle.webapp.base.plugins import ViewPlugin
159
from ivle.webapp.errors import NotFound
157
161
# The user must send this declaration message to ensure they acknowledge the
159
163
USER_DECLARATION = "I accept the IVLE Terms of Service"
170
"""Handler for the Console Service AJAX backend application."""
171
if req.user is None and req.path != 'activate_me':
173
class UserServiceView(BaseView):
174
def __init__(self, req, path):
175
if len(path) > 0 and path[-1] == os.sep:
176
self.path = path[:-1]
180
def authorize(self, req):
173
181
# XXX: activate_me isn't called by a valid user, so is special for now.
174
req.throw_error(req.HTTP_FORBIDDEN,
175
"You are not logged in to IVLE.")
176
if len(req.path) > 0 and req.path[-1] == os.sep:
180
# The path determines which "command" we are receiving
181
fields = req.get_fieldstorage()
183
func = actions_map[req.path]
185
req.throw_error(req.HTTP_BAD_REQUEST,
186
"%s is not a valid userservice action." % repr(req.path))
182
if req.path == 'activate_me' and get_user_details(req) is not None:
184
return req.user is not None
186
def render(self, req):
187
# The path determines which "command" we are receiving
188
fields = req.get_fieldstorage()
190
func = actions_map[self.path]
195
class Plugin(ViewPlugin):
197
('userservice/*path', UserServiceView)
189
200
@require_method('POST')
190
201
def handle_activate_me(req, fields):
206
217
their acceptance). It must only be called through a POST request.
209
# XXX: Very special because we don't have a valid user, so req.user is
211
user = get_user_details(req)
214
req.throw_error(req.HTTP_FORBIDDEN,
215
"You are not logged in to IVLE.")
219
222
declaration = fields.getfirst('declaration')