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

« back to all changes in this revision

Viewing changes to www/apps/userservice/__init__.py

Merge from new-dispatch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
146
146
import ivle.database
147
147
from ivle import (util, chat, caps)
148
148
from ivle.conf import (usrmgt_host, usrmgt_port, usrmgt_magic)
 
149
from ivle.dispatch.login import get_user_details
149
150
import ivle.pulldown_subj
150
151
 
151
152
from ivle.rpc.decorators import require_method, require_cap
167
168
 
168
169
def handle(req):
169
170
    """Handler for the Console Service AJAX backend application."""
170
 
    if req.user is None:
171
 
        # Not logged in
 
171
    if req.user is None and req.path != 'activate_me':
 
172
        # Not logged in.
 
173
        # XXX: activate_me isn't called by a valid user, so is special for now.
172
174
        req.throw_error(req.HTTP_FORBIDDEN,
173
175
        "You are not logged in to IVLE.")
174
176
    if len(req.path) > 0 and req.path[-1] == os.sep:
203
205
    "accepting" the terms - at least this way requires them to acknowledge
204
206
    their acceptance). It must only be called through a POST request.
205
207
    """
 
208
 
 
209
    # XXX: Very special because we don't have a valid user, so req.user is
 
210
    # None.
 
211
    user = get_user_details(req)
 
212
 
 
213
    if user is None:
 
214
        req.throw_error(req.HTTP_FORBIDDEN,
 
215
        "You are not logged in to IVLE.")
 
216
 
206
217
    try:
207
218
        try:
208
219
            declaration = fields.getfirst('declaration')
220
231
            # Check that the user's status is "no_agreement".
221
232
            # (Both to avoid redundant calls, and to stop disabled users from
222
233
            # re-enabling their accounts).
223
 
            if req.user.state != "no_agreement":
 
234
            if user.state != "no_agreement":
224
235
                req.throw_error(req.HTTP_BAD_REQUEST,
225
236
                "You have already agreed to the terms.")
226
237
            # Write state "pending" to ensure we don't try this again
227
 
            req.user.state = u"pending"
 
238
            user.state = u"pending"
228
239
        except:
229
240
            req.store.rollback()
230
241
            raise
233
244
        # Get the arguments for usermgt.activate_user from the session
234
245
        # (The user must have already logged in to use this app)
235
246
        args = {
236
 
            "login": req.user.login,
 
247
            "login": user.login,
237
248
        }
238
249
        msg = {'activate_user': args}
239
250
 
254
265
            status = 'failure'
255
266
        
256
267
        if status == 'okay':
257
 
            req.user.state = u"enabled"
 
268
            user.state = u"enabled"
258
269
        else:
259
270
            # Reset the user back to no agreement
260
 
            req.user.state = u"no_agreement"
 
271
            user.state = u"no_agreement"
261
272
            req.store.commit()
262
273
 
263
274
        # Write the response