Example #1
0
def handle_upload_finderinfo():
    json_data = json.loads(request.get_data().decode('utf-8'))
    username, objuuid = json_data['username'], json_data['uuid']
    username = mc.decrypt(username)
    mc.nofetchall_sql('update Lost set findername=%s where objuuid=%s',
                      (username, objuuid))
    return 'True'
Example #2
0
def handle_query_maskcheck(username,objuuid):
    json_data = json.loads(request.get_data().decode('utf-8'))
    path = basepath + objuuid
    if os.path.exists(path) == False:
        return 'There is no such thing!'
    fr = open(path + '/data.txt', 'rb')
    answer = json.loads(fr.read())
    len_sum,dis_sum = 0,0
    for item in json_data:
        itemjson = json.loads(json_data[item])
        for jtem in itemjson:
            # dis_sum+=dist(answer[item][jtem],itemjson[jtem])
            # len_sum+=len(answer[item][jtem])+len(itemjson[jtem])
            best_dis, best_len, high = 0, 0, 0
            for item_ans in answer:
                for jtem_ans in answer[item]:
                    dis = dist(answer[item_ans][jtem_ans],itemjson[jtem])
                    lth = len(answer[item_ans][jtem_ans])+len(itemjson[jtem])
                    rate = (dis+1)/(lth+1)
                    if rate > high:
                        best_dis, best_len, high =dis,lth,rate
            dis_sum+=best_dis
            len_sum+=best_len

    if (dis_sum+1)/(len_sum+1)<0.8:
        r=mc.nofetchall_sql('UPDATE Lost SET ownername=%s WHERE objuuid=%s',(username,objuuid))
        if r==0:
            print('oops! no such obj')
        mc.nofetchall_sql('UPDATE Lost SET apply="1" WHERE objuuid=%s',(objuuid))
        return 'True'
    else:
        return 'False'
Example #3
0
def handle_query_qrcode_anti(rand):
    jdata = json.loads(request.get_data().decode('utf-8'))
    print(jdata)
    username, passwd, dscpt = jdata['username'], jdata['password'], jdata['description']
    if not mc.is_password_right(username,passwd):
        return send_file(blank_img,as_attachment=True)
    print(username+'gets a qrcode with description: '+dscpt)
    content=username +'*'+ dscpt+'*'+(uuid.uuid1().__str__().replace('-',''))
    code='mark'+mc.encrypt(content)
    mc.nofetchall_sql('insert into Anti_qrcode(username,qrcode) values(%s,%s)',(username,code))
    # qrcode.make(code).resize(qrcode_size).save(qrimg_path)
    qrcode.make(code).save(qrimg_path)
    return send_file(qrimg_path,as_attachment=True)
Example #4
0
def insert_mysql(uuid, path):
    fr = open(path + '/data.txt', 'r')
    item_info = json.loads(fr.read())
    print(item_info)
    hiddeninfo = ' '
    mask_num = item_info['mask_num']
    for i in range(0, int(mask_num)):
        mask = item_info['mask' + str(i)]
        block_num = mask['block_num']
        for j in range(0, int(block_num)):
            hiddeninfo += ' ' + mask['blank' + str(j)]
    mc.nofetchall_sql(
        'insert into Lost(objuuid, lostdate, description, hiddeninfo) values(%s,%s,%s,%s)',
        (uuid, item_info['time'], item_info['description'], hiddeninfo))
def handle_upload_pass():
    jdata = json.loads(request.get_data().decode('utf-8'))
    username, objuuid = jdata['username'], jdata['targetuuid']
    print(username + ' thinks ' + objuuid + ' is right!')
    r = mc.query_sql(
        'select distinct username, targetname from Messages where objuuid=%s',
        (objuuid))
    if username == r[0][0]:
        targetname = r[0][1]
    else:
        targetname = r[0][0]
    mc.nofetchall_sql('update Lost set ownername=%s where objuuid=%s',
                      (targetname, objuuid))
    return 'True'
def handle_upload_msg():
    jdata = json.loads(request.get_data().decode('utf-8'))
    username, objuuid, message, time = jdata['username'], jdata[
        'targetuuid'], jdata['message'], jdata['time']
    r = mc.query_sql(
        'select distinct username, targetname from Messages where objuuid=%s',
        (objuuid))
    if len(r) == 0:
        r = mc.query_sql(
            'select distinct findername from Lost where objuuid=%s', (objuuid))
    if len(r) == 0:
        return 'True'
    if username == r[0][0]:
        targetname = r[0][1]
    else:
        targetname = r[0][0]
    print(
        username + ' sent ' + message + ' to ' + targetname + ' about ' +
        objuuid + 'at time:', time)
    mc.nofetchall_sql(
        'insert into Messages(username, targetname, message,time, objuuid) values(%s,%s,%s,%s,%s)',
        (username, targetname, message, str(time), objuuid))
    return 'True'
Example #7
0
def handle_query_qrcode_lost(rand):
    jdata = json.loads(request.get_data().decode('utf-8'))
    print(jdata)
    username, itemuuid = jdata['useruuid'], jdata['itemuuid']
    sql_select=('select * from Lost where objuuid=%s and ownername=%s',(itemuuid,username))
    sql_update=('update Lost set apply="1" where objuuid=%s and ownername=%s',(itemuuid,username))
    r=mc.query_sql(*sql_select)
    if r==0:
        print('-'*6)
        print(sql_select)
        return send_file(blank_img,as_attachment=True)
    r=mc.nofetchall_sql(*sql_update)
    if r==0:
        print('bad update')
    code='fetc'+itemuuid
    # qrcode.make(code).resize(qrcode_size).save(qrimg_path)
    qrcode.make(code).save(qrimg_path)
    return send_file(qrimg_path,as_attachment=True)