2
# Copyright (C) 2007-2008 The University of Melbourne
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
from common import (util, chat)
30
# TODO: Config these in setup.py
31
USERMGT_HOST = "localhost"
33
USERMGT_MAGIC = "magicuser"
35
# The user must send this declaration message to ensure they acknowledge the
37
USER_DECLARATION = "I accept the IVLE Terms of Service"
40
"""Handler for the Console Service AJAX backend application."""
41
if len(req.path) > 0 and req.path[-1] == os.sep:
45
# The path determines which "command" we are receiving
46
if req.path == "createme":
49
req.throw_error(req.HTTP_BAD_REQUEST)
51
def handle_createme(req):
52
"""Create the jail, svn, etc, for the currently logged in user (this is
53
put in the queue for usermgt to do).
54
This will block until usermgt returns, which could take seconds to minutes
55
in the extreme. Therefore, it is designed to be called by Ajax, with a
56
nice "Please wait" message on the frontend.
58
This will signal that the user has accepted the terms of the license
59
agreement, and will result in the user's database status being set to
60
"enabled". (Note that it will be set to "pending" for the duration of the
63
As such, it takes a single POST field, "declaration", which
64
must have the value, "I accept the IVLE Terms of Service".
65
(Otherwise users could navigate to /userservice/createme without
66
"accepting" the terms - at least this way requires them to acknowledge
67
their acceptance). It must only be called through a POST request.
69
if req.method != "POST":
70
req.throw_error(req.HTTP_BAD_REQUEST)
71
fields = req.get_fieldstorage()
73
declaration = fields.getfirst('declaration')
74
except AttributeError:
75
req.throw_error(req.HTTP_BAD_REQUEST)
76
if declaration != USER_DECLARATION:
77
req.throw_error(req.HTTP_BAD_REQUEST)
79
# Get the arguments for usermgt.create_user from the session
80
# (The user must have already logged in to use this app)
81
session = req.get_session()
83
"username": session['login_name'],
84
"uid": session['unixid'],
86
msg = {'create_user': args}
88
response = chat.chat(USERMGT_HOST, USERMGT_PORT, msg, USERMGT_MAGIC,
90
req.content_type = "text/plain"