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

« back to all changes in this revision

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

  • Committer: dcoles
  • Date: 2008-07-10 02:36:41 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:842
Userservice: Made the userservice more robust so if usrmgt-server fails to 
respond (down or ignores connections due do bad magickey, etc), the user will 
be reset back to no_agreement and thus will not be allowed to log in.

Show diffs side-by-side

added added

removed removed

Lines of Context:
175
175
        }
176
176
        msg = {'activate_user': args}
177
177
 
178
 
        response = chat.chat(usrmgt_host, usrmgt_port, msg, usrmgt_magic,
179
 
            decode = False)
180
 
        # Write to the user's session to allow them to be activated
181
 
        req.user.state = "enabled"
 
178
        # Try and contact the usrmgt server
 
179
        try:
 
180
            response = chat.chat(usrmgt_host, usrmgt_port, msg, usrmgt_magic)
 
181
        except cjson.DecodeError:
 
182
            # Gave back rubbish - set the response to failure
 
183
            response = {'response': 'usrmgt-failure'}
 
184
 
 
185
        # Get the staus of the users request
 
186
        try:
 
187
            status = response['response']
 
188
        except KeyError:
 
189
            status = 'failure'
 
190
        
 
191
        if status == 'okay':
 
192
            req.user.state = "enabled"
 
193
        else:
 
194
            # Reset the user back to no agreement
 
195
            req.user.state = "no_agreement"
 
196
            db.update_user(req.user.login, state="no_agreement")
 
197
 
 
198
 
 
199
        # Update the users state
182
200
        session = req.get_session()
183
201
        session['user'] = req.user
184
202
        session.save()
 
203
 
185
204
        # Write the response
186
205
        req.content_type = "text/plain"
187
 
        req.write(response)
 
206
        req.write(cjson.encode(response))
188
207
    finally:
189
208
        db.close()
190
209