Пример #1
0
def change_pass():
    password = request.forms.get("password")
    newpass = request.forms.get("newpassword")
    if not newpass:
        newpass = password
    doc = request.forms.get("doc")
    old = models.get("password:%s" % doc)
    if not old:
        old = ""
    if old != password:
        return "error"
    models.set("password:%s" % doc, newpass)
    bottle.redirect("/pass/%s/%s/" % (newpass, doc))
Пример #2
0
def change_pass():
    password = request.forms.get('password')
    newpass = request.forms.get('newpassword')
    if not newpass:
        newpass = password
    doc = request.forms.get('doc')
    old = models.get('password:%s' % doc)
    if not old:
        old = ''
    if old != password:
        return 'error'
    models.set('password:%s' % doc, newpass)
    bottle.redirect('/pass/%s/%s/' % (newpass, doc))
Пример #3
0
def api(request):
    if not request.body:
        keys = request.GET.keys()
        if keys:
            data = {'action': 'get', 'data': {}}
            for key in keys:
                data['data'][key] = request.GET[key]
        else:
            context = RequestContext(request, {
                'settings': settings,
                'works': models.works.count(),
                'files': models.files.count(),
            })
            return render_to_response('index.html', context)
    else:
        data = json.loads(request.body)
    if data['action'] == 'login':
        response = login(request, data['data']['username'], data['data']['password'])
    elif data['action'] == 'get':
        response = get(data['data'])
    elif data['action'] == 'set':
        if request.user.is_anonymous():
            response = {'error': 'permission denied'}
        else:
            q = data['data']
            q['user'] = request.user.username
            r = models.set(**q)
            response = get(data['data']['query'])
    elif data['action'] == 'log':
        response = log(data['data'])
    return render_to_json_response(response)
Пример #4
0
def update(doc, parent, user, version, diff):
    if not diff:
        return
    models.lock_acquire(doc)
    now = time.time()
    patch = models.get(doc)
    if not patch:
        patch = []
    pre = []
    version_count = models.get('version:%s:%s' % (user, doc))
    if not version_count:
        version_count = 0
    version_max = models.get('versionmax:%s:%s' % (user, doc))
    if not version_max:
        version_max = 0
    version_time = models.get('versiontime:%s:%s' % (user, doc))
    if not version_time:
        version_time = 0
    same = []
    if parent != version_time:
        models.set('version:%s:%s' % (user, doc), 1, now + 60)
        models.set('versionmax:%s:%s' % (user, doc), version, now + 60)
        models.set('versiontime:%s:%s' % (user, doc), parent, now + 60)
        if version == 1:
            same = [(version, diff)]
        else:
            models.set('versions:%s:%s' % (user, doc), [(version, diff)],
                       now + 60)
    else:
        same = models.get('versions:%s:%s' % (user, doc))
        if not same:
            same = []
        version_count += 1
        models.set('version:%s:%s' % (user, doc), version_count, now + 60)
        if version > version_max:
            version_max = version
        models.set('versionmax:%s:%s' % (user, doc), version_max, now + 60)
        if version_count == version_max:
            same.append((version, diff))
            models.delete('versions:%s:%s' % (user, doc))
        else:
            models.set('versions:%s:%s' % (user, doc),
                       same + [(version, diff)], now + 60)
            same = []
    if not same:
        models.lock_release(doc)
        return
    same = sorted(same)
    version = same[0][0]
    for i in reversed(patch):
        if i['timestamp'] == parent or (i['user'] == user
                                        and i['version'] + 1 == version):
            break
        pre = i['diff'] + pre
    diff = []
    for i in same:
        diff += utils.forward(pre, i[1])
    version = same[-1][0]
    ret = {
        'parent': parent,
        'timestamp': now,
        'user': user,
        'version': version,
        'diff': diff
    }
    models.set(doc,
               filter(lambda x: x['timestamp'] >= now - 60, patch) + [ret])
    models.set('last:%s' % doc, now)
    text = models.get('doc:%s' % doc)
    if text:
        text = text[1]
    else:
        text = ''
    text = utils.text_patch(text, diff)
    models.set('doc:%s' % doc, (now, text))
    models.lock_release(doc)
Пример #5
0
def update(doc, parent, user, version, diff):
    if not diff:
        return
    models.lock_acquire(doc)
    now = time.time()
    patch = models.get(doc)
    if not patch:
        patch = []
    pre = []
    version_count = models.get('version:%s:%s' % (user, doc))
    if not version_count:
        version_count = 0
    version_max = models.get('versionmax:%s:%s' % (user, doc))
    if not version_max:
        version_max = 0
    version_time = models.get('versiontime:%s:%s' % (user, doc))
    if not version_time:
        version_time = 0
    same = []
    if parent != version_time:
        models.set('version:%s:%s' % (user, doc), 1, now+60)
        models.set('versionmax:%s:%s' % (user, doc), version, now+60)
        models.set('versiontime:%s:%s' % (user, doc), parent, now+60)
        if version == 1:
            same = [(version, diff)]
        else:
            models.set('versions:%s:%s' % (user, doc), [(version, diff)], now+60)
    else:
        same = models.get('versions:%s:%s' % (user, doc))
        if not same:
            same = []
        version_count += 1
        models.set('version:%s:%s' % (user, doc), version_count, now+60)
        if version > version_max:
            version_max = version
        models.set('versionmax:%s:%s' % (user, doc), version_max, now+60)
        if version_count == version_max:
            same.append((version, diff))
            models.delete('versions:%s:%s' % (user, doc))
        else:
            models.set('versions:%s:%s' % (user, doc), same+[(version, diff)], now+60)
            same = []
    if not same:
        models.lock_release(doc)
        return
    same = sorted(same)
    version = same[0][0]
    for i in reversed(patch):
        if i['timestamp'] == parent or (i['user'] == user and i['version']+1 == version):
            break
        pre = i['diff']+pre
    diff = []
    for i in same:
        diff += utils.forward(pre, i[1])
    version = same[-1][0]
    ret = {'parent': parent, 'timestamp': now, 'user': user, 'version': version, 'diff': diff}
    models.set(doc, filter(lambda x:x['timestamp']>=now-60, patch)+[ret])
    models.set('last:%s' % doc, now)
    text = models.get('doc:%s' % doc)
    if text:
        text = text[1]
    else:
        text = ''
    text = utils.text_patch(text, diff)
    models.set('doc:%s' % doc, (now, text))
    models.lock_release(doc)