예제 #1
0
def wx_update_password():
    password=request.values.get('password')
    openid=request.values.get('openid')
    sql = 'update wx_user set password="******" where wx_id="'+openid+'"'
    cursor.execute(sql)
    database.commit()
    return jsonify({'status':'success'}) 
예제 #2
0
def change_phones():
    userid = request.form.get('userID')
    # oldPhone = request.form.get('oldPhone')
    newPhone = request.form.get('newPhone')
    mailcode = request.form.get('mailcode')
    usermail = request.form.get('userMail')  #用户接收验证码的邮箱
    codeKey = "" + usermail + ":code"
    code = r.get(codeKey)
    if mailcode == '%s' % code:

        if len(r.keys('wx_user*')) != 0:
            for k in r.scan_iter('wx_user*'):
                r_username = r.hget(k, 'name')
                if r.get(userid) == r_username:
                    user_infor = {'phone': newPhone}
                    r.hmset(k, user_infor)
                    break
        sql = 'update wx_user set phone="' + newPhone + '" where name="' + r.get(
            userid) + '"'
        cursor.execute(sql)
        database.commit()

        return ("0")
    else:
        return ("1")
예제 #3
0
def register():
    openid = request.values.get('openid')
    username = request.values.get('name')

    id = wx_user.query.filter(wx_user.wx_id == openid).first()
    if id:
        return '该用户已注册'
    else:
        for k in r.scan_iter('wx_user*'):
            r.delete(k)
        user = wx_user(name=username,
                       wx_id=openid,
                       phone='无',
                       email='无',
                       password='******',
                       info_number=0,
                       control_power=0)
        db.session.add(user)
        db.session.commit()

        for k in r.scan_iter('wx_user*'):
            r.delete(k)
        wxuser = wx_user.query.filter(wx_user.wx_id == openid).first()
        id = wxuser.id
        sql = 'select * from upload_img'
        cursor.execute(sql)
        image_id = cursor.fetchall()
        for i in image_id:
            unread = "insert into information(user_id,image_id,equip_id) VALUE (%s,%s,%s)" % (
                id, i[0], i[4])
            # unread = information(user_id=id,image_id=i[0],equip_id=i[4])
            cursor.execute(unread)
        database.commit()
        return ''
예제 #4
0
def del_unread_data():
    userid = request.args.get('userID')
    infor_id = request.args.get('inforID')
    read_flag = request.args.get('read_flag')
    if read_flag == 'unread_id':
        user_name = r.get(userid)
        wu = wx_user.query.filter(wx_user.name == user_name).first()  #获取用户名
        wxuser_id = wu.id  #获取用户ID
        sql='delete from information where image_id=%s and user_id=%s' %(infor_id,wxuser_id)
        cursor.execute(sql)
        database.commit()
    data = srch_hash_data('imgs','id',infor_id)
    return data
예제 #5
0
def wx_del_unreaddata():
    openid = request.values.get('openid')
    wxuser=wx_user.query.filter(wx_user.wx_id==openid).first()
    wxuser_id=wxuser.id
    id=request.values.get('id')
    sql='delete from information where image_id=%s and user_id=%s' %(id,wxuser_id)
    try:
        cursor.execute(sql)
    except:
        database.ping(reconnect=True)
        cursor.execute(sql)
    
    database.commit()
    return ''
예제 #6
0
def wx_upload_count():
    wxuser=wx_user.query.filter(wx_user.wx_id==openid).first()    #获取用户名

    wxuser_id=wxuser.id     #将用户id当成上传id
    
    img_count=request.values.get('img_count')
    equip_id=request.values.get('equip_id')
    content=request.values.get('content')
    tittle=request.values.get('tittle')
    # upload_data=upload_img(user_id=wxuser.id,number=img_count)#将当前用户的wx_user.id作为upload_img的user_id
    upload_data=upload_img(user_id=wxuser_id,number=img_count,equip_id=equip_id,image_desc=content,image_title=tittle)
    db.session.add(upload_data)
    db.session.commit()

    upoload=upload_img.query.filter(upload_img.user_id==wxuser_id).order_by(upload_img.date.desc()).first()#获取刚刚上传图片数据的id
    image_id=upoload.id#获取当前上传用户的id

    sql='select id from wx_user'#查询所有用户的id
    try:
        cursor.execute(sql)
    except:
        database.ping(reconnect=True)
        cursor.execute(sql)
    
    
    user_id=cursor.fetchall()#获取所有用户的id

    #使用for/in循环对所有用户添加未读数据
    for (i,) in user_id:
        if(i==wxuser_id):
            continue

        info_data=information(user_id=i,image_id=image_id,equip_id=equip_id)#设备equip_id目前手动设置
        db.session.add(info_data)
        db.session.commit() 

        #将对应的设备未读信息数加一
        sql='update wx_user set info_number=info_number+1 where id=%s' %i
        cursor.execute(sql)
        database.commit()

    return ''
예제 #7
0
def wx_update_mail():
    openid=request.values.get('openid')
    newmail = request.form.get('newmail')
    mailcode = request.form.get('mailcode') 
    codeKey = ""+ newmail +":code"
    code = r.get(codeKey)
    isveri=request.form.get('isveri')
    if isveri:
        if mailcode =='%s' % code:
            return jsonify({'status':'success'}) 
        else:
            return jsonify({'status':'fail'}) 
    else:
        if mailcode =='%s' % code:
            sql = 'update wx_user set email="'+newmail+'" where wx_id="'+openid+'"'
            cursor.execute(sql)
            database.commit()
            return jsonify({'status':'success'}) 
        else:
            return jsonify({'status':'fail'}) 
예제 #8
0
def changedata():
    userid = request.args.get('id')
    name = request.args.get('name')
    phone = request.args.get('phone')
    email = request.args.get('email')
    u_name = '\'%s\'' % name
    u_phone = '\'%s\'' % phone
    u_mail = '\'%s\'' % email
    if len(r.keys('wx_user*')) != 0:
        for k in r.scan_iter('wx_user*'):
            r_userid = r.hget(k, 'id')
            if userid == r_userid:
                print("更新缓存")
                user_infor = {'name': name, 'phone': phone, 'email': email}
                r.hmset(k, user_infor)
    sql = 'update wx_user set name=%s,phone=%s,email=%s where id=%s' % (
        u_name, u_phone, u_mail, userid)
    cursor.execute(sql)
    database.commit()
    json_data = srch_hash_data('wx_user', 'init', 'None')
    return json_data
예제 #9
0
 def update_info(self):
     sql = 'update upload_img set number="' + self.number + '" where equip_id="' + self.equip_id + '" and number=0'
     cursor.execute(sql)
     database.commit()
예제 #10
0
    def re(self, username, user_id, t):
        count = 0
        flag = False  # 循环读取的标识
        t0 = time.time()
        basepath = os.path.split(os.path.dirname(__file__))[0]
        while 1:  # 循环接收文件
            length = 0  # 已接受文件长度
            if count == 0:  # count说明传过来的是一个文件的文件名文件大小等信息
                recived = self.ws.receive()  # 接收信息
                if recived == None:  # 当接收到的数据为空说明没有传输过的文件,退出循环读取文件
                    print("目前用户还没有发送信息请等候:")
                    break
                rec = str(recived, encoding="utf8", errors='ignore')
                self.ws.send("0")
                filename, file_size, file_format = rec.split(SEPARATOR)
                # 根据分隔符分割各传过来的信息,即获取文件名,文件大小,用户名,设备ID
                file_size, afile_size = file_size.split(",")
                print(f"文件名:{afile_size}<-------->文件大小:{file_size}")
                filename = filename.split("/")[-1]  # 获取带扩招名的文件名
                file_size = int(file_size)
                afile_size = int(afile_size)
                if file_format == ".txt":
                    dire = "data/"

                else:
                    dire = "images/"

                file_path = Path(
                    os.path.join(basepath,
                                 "static/" + dire + username))  # 根据用户名创建文件夹
                base_path = Path(
                    os.path.join(basepath, "static/" + dire + username + "/" +
                                 t))  # 根据每次上传文件的时间戳创建文件夹
                if file_path.exists():  # 判断以用户名命名的文件夹是否存在
                    if base_path.exists(
                    ):  # 当以用户名命名的文件夹存在,则判断以当前获取的时间戳命名的文件夹是否存在
                        if os.path.exists(filename):  # 判断发送的文件是否已经存在
                            # self.send(f"文件{filename}已经存在!")
                            break
                        else:
                            file_name = "static/" + dire + username + "/" + t + "/" + filename
                            filename = os.path.join(basepath, "static/" +
                                                    dire + username + "/" + t +
                                                    "/" + filename)  #路径拼接
                            # 设置图片的真实存储路径
                    else:  # 如果以用户名命名的文件存在,但不存在以当前获取的时间戳命名的文件夹,
                        #则为创建文件夹,并为其创建一个获取的时间戳的文件夹,用于存放其发送到服务器的图片
                        os.mkdir(base_path)
                        file_name = "static/" + dire + username + "/" + t + "/" + filename
                        filename = os.path.join(basepath, "static/" + dire +
                                                username + "/" + t + "/" +
                                                filename)  #路径拼接
                else:  # 如果以用户名命名的文件夹不存在,则说明压根没登录过则为其创建一个以用户命名的文件夹,
                    # 并将获取其传输过来的时间戳为其创建一个文件用于存放本次上传的图片
                    os.mkdir(file_path)
                    os.mkdir(base_path)
                    file_name = "static/" + dire + username + "/" + t + "/" + filename
                    filename = os.path.join(basepath,
                                            "static/" + dire + username + "/" +
                                            t + "/" + filename)  #路径拼接

            if Path(filename).exists():  # 判断发送的文件是否已经存在
                local_size = os.path.getsize(filename)
                if local_size != afile_size:
                    # self.send(f"文件{filename}已经存在!")
                    pro_1 = tqdm.tqdm(range(file_size),
                                      f"接收续传文件",
                                      unit="B",
                                      unit_divisor=1024)  # 设置进度调条
                    with open(filename, "ab") as f:  # 写文件
                        for _ in pro_1:  # 根据进度条读取数据,即每次读取1024B的数据
                            bytes_read = self.ws.receive()
                            if bytes_read == None:
                                flag = True
                                print("第二次死了")
                                break
                            f.write(bytes_read)
                            length += len(bytes_read)  # 已经读取的多少长度的文件
                            self.ws.send(f"{length}")
                            pro_1.update(len(bytes_read))  # 更新进度条
                            count += 1  # 当count不为零说明开始接收文件内容
                            print(f"第二次接收了{length}字节------------",
                                  f"大小为{file_size}字节")
                            if length == file_size:  # 文件接收完
                                print("第二次正常")
                                flag = False
                                break  #退出for循环但没有退出with的循环读取

            else:
                pro_2 = tqdm.tqdm(range(afile_size),
                                  f"接收第1次文件",
                                  unit="B",
                                  unit_divisor=1024)  # 设置进度调条
                with open(filename, "wb") as f:  # 写文件
                    for _ in pro_2:  # 根据进度条读取数据,即每次读取1024B的数据
                        bytes_read = self.ws.receive()
                        if bytes_read == None:
                            flag = True
                            print("第一次死了")
                            break
                        f.write(bytes_read)
                        length += len(bytes_read)  # 已经读取的多少长度的文件
                        self.ws.send(f"{length}")
                        pro_2.update(len(bytes_read))  # 更新进度条
                        count += 1  # 当count不为零说明开始接收文件内容

                        print(f"第一次接收了{length}字节------{count}------",
                              f"文件总大小为{afile_size}字节")
                        if length == afile_size:  # 文件还没接收完
                            print("第一次正常")
                            flag = False
                            break  #退出for循环但没有退出with的循环读取

            local_size = os.path.getsize(filename)
            if (flag == False) and (
                    local_size == file_size):  # 一个文件已经接受完毕,退出循环读取但并没有退出最外层循
                print("数据处理")
                if file_format == ".txt":
                    upoload = upload_img.query.filter(
                        upload_img.user_id == user_id).order_by(
                            upload_img.date.desc()).first()  # 获取刚刚上传图片数据的id
                    image_id = upoload.id  # 获取当前上传用户的id
                    file_name = '\'%s\'' % file_name
                    sql = 'update imgs set data_path=%s where upload_id=%s' % (
                        file_name, image_id)
                    cursor.execute(sql)
                    database.commit()
                else:
                    upoload = upload_img.query.filter(
                        upload_img.user_id == user_id).order_by(
                            upload_img.date.desc()).first()  # 获取刚刚上传图片数据的id
                    image_id = upoload.id  # 获取当前上传用户的id
                    img = imgs(upload_id=image_id,
                               file_path=file_name,
                               data_path=0)
                    db.session.add(img)
                    db.session.commit()
                break  #退出while循环