19
19
# Author: Matt Giuca
22
# Provides an Ajax service for handling user management requests.
23
# This includes when a user logs in for the first time.
25
# NOTE: This app does NOT require authentication. This is because otherwise it
26
# would be blocked from receiving requests to activate when the user is trying
29
# It must do its own authentication and authorization.
27
from common import (util, chat)
37
from common import (util, chat, caps)
30
40
# TODO: Config these in setup.py
40
50
"""Handler for the Console Service AJAX backend application."""
51
if req.username is None:
53
req.throw_error(req.HTTP_FORBIDDEN)
41
54
if len(req.path) > 0 and req.path[-1] == os.sep:
42
55
path = req.path[:-1]
45
58
# The path determines which "command" we are receiving
46
if req.path == "createme":
59
if req.path == "activate_me":
60
handle_activate_me(req)
49
62
req.throw_error(req.HTTP_BAD_REQUEST)
51
def handle_createme(req):
64
def handle_activate_me(req):
52
65
"""Create the jail, svn, etc, for the currently logged in user (this is
53
66
put in the queue for usermgt to do).
54
67
This will block until usermgt returns, which could take seconds to minutes
66
79
"accepting" the terms - at least this way requires them to acknowledge
67
80
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"
85
if req.method != "POST":
86
req.throw_error(req.HTTP_BAD_REQUEST)
87
fields = req.get_fieldstorage()
89
declaration = fields.getfirst('declaration')
90
except AttributeError:
91
req.throw_error(req.HTTP_BAD_REQUEST)
92
if declaration != USER_DECLARATION:
93
req.throw_error(req.HTTP_BAD_REQUEST)
95
# TODO: Check the DB that the user's status is "no_agreement".
96
# (Both to avoid redundant calls, and to stop disabled users from
97
# re-enabling their accounts).
99
# Get the arguments for usermgt.create_user from the session
100
# (The user must have already logged in to use this app)
101
session = req.get_session()
103
"login": req.username,
105
msg = {'activate_user': args}
107
response = chat.chat(USERMGT_HOST, USERMGT_PORT, msg, USERMGT_MAGIC,
109
# TODO: Figure out a way to let the user be "enabled" in this session.
110
# (Would require a write to the session?)
111
req.content_type = "text/plain"