예제 #1
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)
        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 ''
예제 #2
0
    def ctreate_ThreadPool(self):
        user_phone = request.form.get('userPhone')
        user_name = request.form.get('userName')
        # t = request.form.get('uploadTime')
        t = '2021'
        desc = request.form.get('imageDesc')
        theme = request.form.get('imageTitle')
        number = request.form.get('imageCount')

        user = wx_user.query.filter(
            wx_user.phone == user_phone).first()  #获取用户名
        user_id = user.id  #获取用户ID
        print(user_id)
        number = int(number)
        d = Data_deal(user_id, number, desc, theme)
        d.update_info()
        threadPool = ThreadPoolExecutor(max_workers=number,
                                        thread_name_prefix="pro")  # 根据用户上传的文件
        # 一个用户来访问就会开一个线程,然后根据他传过来的图片数量,开启线程池读取文件
        for i in range(number):
            future = threadPool.submit(self.re(user_name, user_id,
                                               t))  # j将线程提交到线程池
        threadPool.shutdown()
        #返回信息给客户端图片接收完毕
        for j in r.scan_iter('imgs*'):
            r.delete(j)
        for k in r.scan_iter('upload_img*'):
            r.delete(k)
예제 #3
0
def web_register(user_name):
    username = request.form.get("username")
    pwd = request.form.get('pwd')
    repwd = request.form.get('repwd')
    userphone = request.form.get("userphone")
    usermail = request.form.get("usermail")
    mailcode = request.form.get('mailcode')
    codeKey = "" + usermail + ":code"
    code = r.get(codeKey)
    # 检验参数完整
    if not all([username, pwd, repwd, userphone, usermail, mailcode]):
        # return jsonify({'status': '失败'}, {'erroMsg': '参数不完整'})
        return ("3")
    else:
        user = wx_user.query.filter(wx_user.name == username).first()
        #找到
        if user:
            return ("2")
        else:
            # 判断邮箱验证码是否正确
            if mailcode == '%s' % code:
                for k in r.scan_iter('wx_user*'):
                    r.delete(k)
                webuser = wx_user(name=username,
                                  email=usermail,
                                  phone=userphone,
                                  password=pwd,
                                  wx_id=1,
                                  info_number=0)
                db.session.add(webuser)
                db.session.commit()
                for k in r.scan_iter('wx_user*'):
                    r.delete(k)
                return ("1")
            else:
                return ("0")
예제 #4
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
예제 #5
0
def get_imagedata():
    if len(r.keys('upload_img*')) == 0:
        sql = 'select distinct * from v_userImgs'
        cursor.execute(sql)
        user_data = cursor.fetchall()
        fields = cursor.description
        column_list = []
        json_list = []
        for i in fields:
            column_list.append(i[0])
        for row in user_data:
            data = {}
            for i in range(len(column_list)):
                data[column_list[i]] = row[i]
            json_list.append(data)
            imgsData = json.dumps(json_list,
                                  ensure_ascii=False,
                                  cls=CJsonEncoder)
        for i in range(len(user_data)):
            imgs_infor = {
                'name': user_data[i][0],
                'id': user_data[i][1],
                'user_id': user_data[i][2],
                'number': user_data[i][3],
                'date': user_data[i][4].strftime("%Y-%m-%d %H:%M:%S"),
                'equip_id': user_data[i][5],
                'image_desc': user_data[i][7],
                'image_title': user_data[i][6]
            }
            r.hmset('upload_img:%d' % (user_data[i][1]), imgs_infor)
            r.expire('upload_img:%d' % (user_data[i][1]), 432000)
        return imgsData
    else:
        imgsdata = []
        for k in r.scan_iter('upload_img*'):
            data = r.hgetall(k)
            imgsdata.append(data)
        imgsdata = tuple(imgsdata)
        imgsdata = json.dumps(imgsdata, ensure_ascii=False, cls=CJsonEncoder)
        return imgsdata
예제 #6
0
def get_userdata():
    if len(r.keys('wx_user*')) == 0:
        sql = 'select * from wx_user'
        cursor.execute(sql)
        user_data = cursor.fetchall()
        fields = cursor.description
        column_list = []
        json_list = []
        for i in fields:
            column_list.append(i[0])
        for row in user_data:
            data = {}
            for i in range(len(column_list)):
                data[column_list[i]] = row[i]
            json_list.append(data)
            userData = json.dumps(json_list,
                                  ensure_ascii=False,
                                  cls=CJsonEncoder)
        for i in range(len(user_data)):
            user_infor = {
                'id': user_data[i][0],
                'name': user_data[i][1],
                'phone': user_data[i][2],
                'email': user_data[i][3],
                'password': user_data[i][4],
                'wx_id': user_data[i][5]
            }
            r.hmset('wx_user:%d' % (user_data[i][0]), user_infor)
            r.expire('wx_user:%d' % (user_data[i][0]), 86400)
        return userData
    else:
        userdata = []
        for k in r.scan_iter('wx_user*'):
            data = r.hgetall(k)
            userdata.append(data)
        userdata = tuple(userdata)
        userdata = json.dumps(userdata, ensure_ascii=False, cls=CJsonEncoder)
        return userdata
예제 #7
0
def change_emails():
    userid = request.form.get('userID')
    newmail = request.form.get('newMail')
    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 = {'email': newmail}
                    r.hset(k, user_infor)
        sql = 'update wx_user set email="' + newmail + '" where name="' + r.get(
            userid) + '"'
        cursor.execute(sql)
        database.commit()

        return ("0")
    else:
        return ("1")