def getRegisterID(request): try: theUUID=request.POST['deviceID'] theName=request.POST['userName'] if len(theUUID) < __uuid_len__ : theUUID=generateUUID(theName) else: deviceOperation.addDevice(theName,theUUID, time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())) return HttpResponse(theUUID) except Exception as e: return HttpResponse('Error:'+str(e))
def generateUUID(theName): def UUIDGenerate(theLen): theUUID='' for i in range(theLen): theUUID += random.choice("ABCDEFGHIGKLMNOPQRSTUVWXYZ1234567890") return theUUID theUUID = UUIDGenerate(__uuid_len__) while(not deviceOperation.addDevice(theName,theUUID, time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))): theUUID = UUIDGenerate(__uuid_len__) return theUUID
def addUser2List(theUUID, userName): if len(__aliveUserDict__) >= __maxUserNum__ and not __aliveUserDict__.has_key(theUUID): return None userInfo={} userInfo["name"]=userName userInfo["visitTime"]=datetime.datetime.now() userInfo["score"]=0 if not __aliveUserDict__.has_key(theUUID): deviceInfo=theUUID.split("%") deviceDID=deviceInfo[0] deviceCreateTime=deviceInfo[1] if not deviceOperation.addDevice(userName,deviceDID,deviceCreateTime): print "failed to add device!" __aliveUserDict__[theUUID]=userInfo return theUUID