Exemplo n.º 1
0
def deviceRemove(deviceId):
    rows,isEof = database.db_select_device(id=deviceId)
    if len(rows)<=0:
        return
    accessKey = rows[0][8]
    row = database.db_select_accessKey(accessKey)
    if len(row) <= 0:# key is not alloced
        return error.ERR_CODE_OK_
    # accessDevices format: 'id1|id2|id3|...'
    accessDevices = row[0][3]
    if accessDevices is None:
        return error.ERR_CODE_OK_

    devices = accessDevices.split(':')
    try:
        devices.remove(str(deviceId))
    except:
        return error.ERR_CODE_OK_
    if len(devices) == 0:
        updDevices = None
    else:
        updDevices = str(devices[0])
        for item in devices[1:]:
            updDevices = updDevices + ":" + str(item)
    return database.db_update_accessKey(accessKey,updDevices)
Exemplo n.º 2
0
def deviceAccess(deviceId, accessKey):
    row = database.db_select_accessKey(accessKey)
    if len(row) <= 0:# key is not alloced
        return error.ERR_CODE_PARAINVALID
    # accessDevices format: 'id1|id2|id3|...'
    accessDevices = row[0][3]
    if accessDevices is not None:
        devices = accessDevices.split(':')
        if len(devices)>=5:#one key can access max 5 devices.
            return error.ERR_CODE_ACCESS_MAX
        for item in devices:
            if deviceId==int(item):
                return error.ERR_CODE_OK_ #already access

    if accessDevices is None:
        updDevices = str(deviceId)
    else:
        updDevices = accessDevices+':'+str(deviceId)
    return database.db_update_accessKey(accessKey,updDevices)