Пример #1
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")
Пример #2
0
def check_users():
    userid = request.form.get('userid')
    if r.get(userid) == None:
        return ("1")
    else:
        username = r.get(userid)
        return ("2")
Пример #3
0
def get_is_data():
    userid = request.args.get('userID')
    eq_id = request.args.get('equipID')
    user_name = r.get(userid)
    wu = wx_user.query.filter(wx_user.name == user_name).first()  #获取用户名
    wxuser_id = wu.id  #获取用户ID
    sql='select image_id from information where user_id=%s and equip_id=%s' %(wxuser_id,eq_id)
    cursor.execute(sql)
    image_id=cursor.fetchall()
    all_id=[]
    unread_id=[]
    for (i,) in image_id:
        unread_id.append(i)
    imgs_id = srch_hash_data('upload_img','equip_id',eq_id)
  
    for i in imgs_id:
        all_id.append(i)
    # 将所有的图片id减去未读图片的id获得已读图片的ID
    is_id=set(all_id)-set(unread_id)
    read_arr=[]
    for i in is_id:
        read_data = srch_hash_data('upload_img','id',str(i))
        read_arr.append(read_data[0][0])
        read_arr.append(read_data[0][1])  
        read_arr.append(read_data[0][2])       
    json_data=json.dumps(read_arr,cls=CJsonEncoder)
    return json_data
Пример #4
0
def web_imgsupload():
    userid = request.form.get('userID')
    user_name = r.get(userid)
    # 获取当前项目所在路径(绝对路径)
    basepath=os.path.split(os.path.dirname(__file__))[0]
    wu = wx_user.query.filter(wx_user.name == user_name).first()  
    wxuser_id = wu.id    #获取用户ID
    image = request.files.getlist('photo')
    for i in range(len(image)):
        # 将图片路径保存到'imgs'数据库中
        image_name = image[i].filename  #获取图片名
        timeArray = time.strptime(datetime.now().strftime('%Y-%m-%d'), "%Y-%m-%d")  
        timeStamp = int(time.mktime(timeArray))  # 转为时间戳
        file = 'static/images/' +user_name + '/'+ str(timeStamp)
        if not os.path.exists(file):
            os.makedirs(file)
        relativePath = file +'/'+ image_name
        upload_path = os.path.join(basepath, relativePath)  #路径拼接
        image[i].save(upload_path)
        #将upload_img的id作为imgs的upload_id
        uploadid = upload_img.query.filter(
            upload_img.user_id == wxuser_id).order_by(
                upload_img.date.desc()).first()
        up_id = uploadid.id  #获取当前上传用户的id,改id作为imgs.upload_id的外键
        img = imgs(upload_id=up_id, file_path=relativePath, data_path=0)
        db.session.add(img)
        db.session.commit()

    return jsonify({'status': 'success'})
Пример #5
0
def upload_count():
    userid = request.form.get('userID')
    user_name = r.get(userid)
    wu = wx_user.query.filter(wx_user.name == user_name).first()  #获取用户名
    wxuser_id = wu.id  #获取用户ID
    img_count = request.form.get('imageCount')
    equipId = request.form.get('equipID')
    equipDesc = request.form.get('imageDesc')
    equipTitle = request.form.get('imageTitle')
    
    upload_data = upload_img(user_id=wxuser_id,number=img_count,equip_id=equipId,
        image_desc=equipDesc,image_title=equipTitle)  #将当前登录用户的id作为upload_img的user_id
    
    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
    cursor.execute(sql)#执行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=equipId)#设备equip_id目前手动设置
        db.session.add(info_data)
        db.session.commit() 

    return ''
Пример #6
0
def web_register(user_name):
    print(user_name)
    username = request.form.get('userName')
    pwd = request.form.get('pwd')
    userphone = request.form.get("userPhone")
    usermail = request.form.get("userMail")
    mailcode = request.form.get('mailCode')
    codeKey = "" + usermail + ":code"
    code = r.get(codeKey)
    user = wx_user.query.filter(wx_user.name == username
                                or wx_user.phone == userphone).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")
Пример #7
0
def change_passwords():
    userid = request.form.get('userID')
    oldpwd = request.form.get('oldpwd')
    newpwd = request.form.get('newpwd')
    # mailcode = request.form.get('mailcode')
    # usermail = request.form.get('userMail') #用户接收验证码的邮箱
    # codeKey = ""+ usermail +":code"
    # code = r.get(codeKey)
    # if mailcode =='%s' % code:
    user_name = r.get(userid)
    user = wx_user.query.filter(wx_user.password == oldpwd
                                and wx_user.name == user_name).first()
    if user:
        if len(r.keys('wx_user*')) != 0:
            for k in r.scan_iter('wx_user*'):
                r_username = r.hget(k, 'name')
                if user_name == r_username:
                    user_infor = {'password': newpwd}
                    r.hmset(k, user_infor)
                    break
        user_update = wx_user.query.filter(
            wx_user.password == oldpwd
            and wx_user.name == user_name).update({'password': newpwd})
        db.session.commit()

        return ("0")
    else:
        return ("1")
Пример #8
0
def get_deserve():
    exist = r.exists('eq_data')
    if exist==0:
        sql = 'select *from equipment'
        cursor.execute(sql)
        
        user_data = cursor.fetchall()
        json_data = json.dumps(user_data, cls=CJsonEncoder)
        r.set('eq_data',json_data)
    else:
        json_data=r.get('eq_data')
    return json_data
Пример #9
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
Пример #10
0
def change_emails():
    user_id = request.form.get('userID')
    new_mail = request.form.get('newMail')
    mail_code = request.form.get('mailcode')  #用户输入的验证码
    user_mail = request.form.get('oldMail')  #用户接收验证码的邮箱
    codeKey = "" + user_mail + ":code"
    code = r.get(codeKey)
    if mail_code == '%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(user_id) == r_username:
                    user_infor = {'email': new_mail}
                    r.hmset(k, user_infor)
                    break
        user = wx_user.query.filter(wx_user.email == user_mail).update(
            {'email': new_mail})
        db.session.commit()

        return ("0")
    else:
        return ("1")
Пример #11
0
def get_equip_data():
    userid = request.args.get('userID')
    user_name = r.get(userid)
    wu = wx_user.query.filter(wx_user.name == user_name).first()  #获取用户名
    wxuser_id = wu.id  #获取用户ID
    equip_unread=[]
    data = r.sort('equip:id',by='equipment:*->id', get=['equipment:*->id'])
    for equip_id in data:           
        sql='select count(*) from information where user_id=%s and equip_id=%s'%(wxuser_id,equip_id)
        cursor.execute(sql)
        one=cursor.fetchall()
        for (i,) in one:
            equip_unread.append(i)
    equip_unread_data=json.dumps(equip_unread)
    return equip_unread_data
Пример #12
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'}) 
Пример #13
0
def getuserval():
    userid = request.args.get('userID')
    userData = srch_hash_data('wx_user', 'name', r.get(userid))
    return userData