131
131
"accepting" the terms - at least this way requires them to acknowledge
132
132
their acceptance). It must only be called through a POST request.
134
if req.method != "POST":
135
req.throw_error(req.HTTP_BAD_REQUEST)
137
declaration = fields.getfirst('declaration')
138
except AttributeError:
139
req.throw_error(req.HTTP_BAD_REQUEST)
140
if declaration != USER_DECLARATION:
141
req.throw_error(req.HTTP_BAD_REQUEST)
143
session = req.get_session()
144
# Check that the user's status is "no_agreement".
145
# (Both to avoid redundant calls, and to stop disabled users from
146
# re-enabling their accounts).
147
if session['state'] != "no_agreement":
148
req.throw_error(req.HTTP_BAD_REQUEST)
150
# Get the arguments for usermgt.activate_user from the session
151
# (The user must have already logged in to use this app)
153
"login": req.username,
155
msg = {'activate_user': args}
157
response = chat.chat(usrmgt_host, usrmgt_port, msg, usrmgt_magic,
159
# TODO: Figure out a way to let the user be "enabled" in this session.
160
# (Would require a write to the session?)
161
req.content_type = "text/plain"
136
if req.method != "POST":
137
req.throw_error(req.HTTP_BAD_REQUEST)
139
declaration = fields.getfirst('declaration')
140
except AttributeError:
141
req.throw_error(req.HTTP_BAD_REQUEST)
142
if declaration != USER_DECLARATION:
143
req.throw_error(req.HTTP_BAD_REQUEST)
145
# Make sure the user's status is "no_agreement", and set status to
146
# pending, within the one transaction. This ensures we only do this
148
db.start_transaction()
151
user_details = db.get_user(req.username)
152
# Check that the user's status is "no_agreement".
153
# (Both to avoid redundant calls, and to stop disabled users from
154
# re-enabling their accounts).
155
if user_details['state'] != "no_agreement":
156
req.throw_error(req.HTTP_BAD_REQUEST)
157
# Write state "pending" to ensure we don't try this again
158
db.update_user(req.username, state="pending")
164
# Get the arguments for usermgt.activate_user from the session
165
# (The user must have already logged in to use this app)
167
"login": req.username,
169
msg = {'activate_user': args}
171
response = chat.chat(usrmgt_host, usrmgt_port, msg, usrmgt_magic,
173
# Write to the user's session to allow them to be activated
175
req.content_type = "text/plain"
164
180
create_user_fields_required = [
165
181
'login', 'fullname', 'rolenm'