Beispiel #1
0
def delete_account(request, **args):
    """Deletes a user's account and attempts to purge their sync data

    It tries the user sync node and doesn't worry overly if the delete
    request fails, as the sync data will eventually be cleaned by other
    methods
    """

    if not check_crumb(request):
        request.errors.append(_('We were unable to process your request. '
                                'Please try again.'))
        return delete_account_form(request)

    data = {'trail': [[None, _('Delete Account')]]}
    auth = request.registry["auth"]
    pwd = request.params['password']
    username = request.session.get('username')

    data['crumb'] = generate_crumb(request)
    if not auth.authenticate_user(request.user, pwd):
        request.errors.append(
                _('We were unable to authenticate your account.'))
        return delete_account_form(request)

    #if this supports a sync cluster, need to purge from there
    if "sync" in request.registry.settings.get('console.modules'):
        sync_config = \
                request.registry.settings.get('config').get_map('sync')
        auth.get_user_info(request.user, ['syncNode'])
        if request.user.get('syncNode'):
            client = SyncClient(sync_config,
                                request.user.get('syncNode'),
                                request.user.get('username'),
                                pwd)
            if not client.delete_data():
                data['alert'] = \
                  _("We were unable to delete your data on the weave node."
                    " Don't worry, it's encrypted on the node and will be"
                    " cleaned up shortly.")

    if not auth.delete_user(request.user, pwd):
        request.errors.append(_('Deleting your account failed unexpectedly. '
                          'Please try again later.'))
        return delete_account_form(request)

    log_cef('Account Deleted', 7,
            request.environ, request.registry.settings, username,
            signature='DeleteUser')
    data['username'] = None
    data['email'] = None
    data['success'] = 1
    username = None

    request.session.delete()
    return data
Beispiel #2
0
    def test_sync_timeout(self):

        def _urlopen(*args, **kw):
            raise urllib2.URLError(socket.timeout)

        old = urllib2.urlopen
        urllib2.urlopen = _urlopen

        client = SyncClient(config)
        assert client.delete_data() == False
        urllib2.urlopen = old