def getUserRedis(token): db = getDb() userDb = db['Users'] userId = redis.get(token) print(userId) if (userId == None): return None userId = ObjectId(userId.decode("utf-8")) exist = userDb.find_one({"_id": userId}) return (exist)
def ftp_login(username, password, ip_address, MongoDB_port, target_id): #target id is ObjectId target_id = ObjectId(target_id.decode("utf-8")) #since parameters are byte we have to convert them to string username = username.decode("utf-8") password = password.decode("utf-8") ip_address = ip_address.decode("utf-8") MongoDB_port = int(MongoDB_port.decode("utf-8")) if (login(username, password, ip_address)): #We should add it to the database! client = MongoClient('localhost', MongoDB_port) db = client['ztp-dev'] post = { "static_report": "", "dynamic_report": "Anonymous login is enabled.", "target": ObjectId(target_id) } db["dynamicreport"].insert_one(post).inserted_id print("anonymous login enabled!") else: print("not enabled!")