예제 #1
0
def add_item_to_list(gid, measurment, sid, session):
    userid = __get_userid_from_key(session)

    if userid == 'BAD_KEY':
        kwlog.log("Invaild session key")
        return "BAD_KEY"
    else:
        if len(gid) == 0 or len(measurment) == 0 or len(sid) == 0:
            kwlog.log("Format of request is invaild")
            return "INVAILD_FORMAT"
        if not MySQL.is_vaild_group(gid):
            kwlog.log("Group ID is not vaild")
            return "INVAILD_GROUP"
        if not MySQL.is_vaild_shopping_list(sid, userid):
            kwlog.log("Invaild shopping list id")
            name = "%s list" % str(userid)
            createList.create_new_list(name, session)
            sid = MySQL.get_shopping_lists(userid)[0][0]
            if not MySQL.insert_item_to_list(sid, gid, measurment, userid):
                kwlog.log("Unable to add item to list")
                return "FAILED_TO_ADD_ITEM"
            else:
                return "ADD_ITEM_COMPLETE"
            return "INVAILD_SHOPPING_LIST"
        if not MySQL.insert_item_to_list(sid, gid, measurment, userid):
            kwlog.log("Unable to add item to list")
            return "FAILED_TO_ADD_ITEM"
        else:
            return "ADD_ITEM_COMPLETE"
예제 #2
0
def add_item_to_list(gid, measurment, sid, session):
    userid =  __get_userid_from_key(session)

    if userid == 'BAD_KEY':
        kwlog.log("Invaild session key")
        return "BAD_KEY"
    else:
        if len(gid) == 0 or len(measurment) == 0 or len(sid) == 0:
            kwlog.log("Format of request is invaild")
            return "INVAILD_FORMAT"
        if not MySQL.is_vaild_group(gid):
            kwlog.log("Group ID is not vaild")
            return "INVAILD_GROUP"
        if not MySQL.is_vaild_shopping_list(sid, userid):
            kwlog.log("Invaild shopping list id")
            name = "%s list" % str(userid)
            createList.create_new_list(name, session)
            sid = MySQL.get_shopping_lists(userid)[0][0]
            if not MySQL.insert_item_to_list(sid, gid, measurment, userid):
                kwlog.log("Unable to add item to list")
                return "FAILED_TO_ADD_ITEM"
            else:
                return "ADD_ITEM_COMPLETE"
            return "INVAILD_SHOPPING_LIST"
        if not MySQL.insert_item_to_list(sid, gid, measurment, userid):
            kwlog.log("Unable to add item to list")
            return "FAILED_TO_ADD_ITEM"
        else:
            return "ADD_ITEM_COMPLETE"
예제 #3
0
def get_list_ID(session_key):
    userid =  __get_userid_from_key(session_key)

    if userid == 'BAD_KEY':
        kwlog.log("Invaild session key")
        return "BAD_KEY"
    else:
        sid = MySQL.get_shopping_list_id_for_user(userid)
        if sid == "NONE":
            name = "%s list" % str(userid)
            createList.create_new_list(name, session_key)
            sid = MySQL.get_shopping_lists(userid)[0][0]
        print(sid)
        return str(sid)
예제 #4
0
파일: getListID.py 프로젝트: mr7657/Backend
def get_list_ID(session_key):
    userid = __get_userid_from_key(session_key)

    if userid == 'BAD_KEY':
        kwlog.log("Invaild session key")
        return "BAD_KEY"
    else:
        sid = MySQL.get_shopping_list_id_for_user(userid)
        if sid == "NONE":
            name = "%s list" % str(userid)
            createList.create_new_list(name, session_key)
            sid = MySQL.get_shopping_lists(userid)[0][0]
        print(sid)
        return str(sid)
예제 #5
0
def service_request(data, connection):
	result = None
	command = value_from_header(data, 'command')
	if command == "Error":
		print(str(data))
		connection.close()
		return
	if command == 'register':
		username = value_from_header(data, 'username')
		fname = value_from_header(data, 'fname')
		lname = value_from_header(data, 'lname')
		email = value_from_header(data, 'email')
		password = value_from_header(data, 'password')
		result = add_new_user(username, fname, lname, email, password.encode("utf-8"))

	if command == "activate":
		code = value_from_header(data, "code")
		result = update_account_activation_stats( code)

	if command == "login":
		username = value_from_header(data, 'username')
		password = value_from_header(data, 'password')
		kwlog.log(str(username + ":"+ password))
		result = login_to_account(username, password.encode("utf-8"))

	if command == "updateaccount":
		sessionkey = value_from_header(data, 'sessionkey')
		fname = value_from_header(data, 'fname')
		lname = value_from_header(data, 'lname')
		email = value_from_header(data, 'email')
		password = value_from_header(data, 'password')
		if fname == "Error":
			fname = ''
		if lname == "Error":
			lname = ''
		if email == "Error":
			email = ''
		if password == "Error":
			password = ''
		result = update_account_information(fname, lname, email, password.encode("utf-8"), sessionkey)
	if command == "additem":
		barcode = value_from_header(data, 'barcode')
		sessionkey = value_from_header(data, 'sessionkey')
		result = replace_commas_with_semicolons(add_new_item(barcode, sessionkey))
	if command == "getitems":
		sessionkey = value_from_header(data, 'sessionkey')
		result = get_item_list(sessionkey)
		result = replace_commas_with_semicolons(result)

	if command == "removeitem":
		product_id = value_from_header(data, 'id')
		sessionkey = value_from_header(data, 'sessionkey')
		result = remove_item(product_id, sessionkey)

	if command == "getrecipes":
                sessionkey = value_from_header(data, 'sessionkey')
                result = replace_commas_with_semicolons(get_list_of_recipes(sessionkey))

	if command == "getingredients":
		sessionkey = value_from_header(data, 'sessionkey')
		recipeid = value_from_header(data, 'recipeid')
		result = get_list_of_ingredients(sessionkey, recipeid)
	if command == "removerecipe":
		recipe_id = value_from_header(data, 'recipeid')
		sessionkey = value_from_header(data, 'sessionkey')
		result = remove_recipe(recipe_id, sessionkey)

	if command == "updaterecipe":
		sessionkey = value_from_header(data, 'sessionkey')
		name = value_from_header(data, 'name')
		recipeid = value_from_header(data, 'recipeid')
		description = value_from_header(data, 'description')
		image = ''
		preptime = value_from_header(data, 'preptime')
		cooktime = value_from_header(data, 'cooktime')
		itemaction = value_from_header(data, 'itemaction')
		groupid = value_from_header(data, 'groupid')
		quantity = value_from_header(data, 'quantity')

		if sessionkey == "Error":
			sessionkey = ""
		if name == "Error":
			name = ""
		if recipeid == "Error":
			recipeid = ""
		if description == "Error":
			description = ""
		if preptime == "Error":
			preptime = ""
		if cooktime == "Error":
			cooktime = ""
		if itemaction == "Error":
			itemaction = ""
		if groupid == "Error":
			groupid = ""
		if quantity == "Error":
			quantity = ""

		item = []
		if groupid != "":
			item = [[groupid, quantity]]
		result = update_recipe(recipeid, name, description, image, preptime, cooktime, item, itemaction, sessionkey)
	if command == "getgrouplist":
		result = replace_commas_with_semicolons_for_groups(get_list_of_generic_items())

	if command == "updateitem":
		sessionkey = value_from_header(data, 'sessionkey')
		expiration = value_from_header(data, 'expiration')
		if expiration == "Error":
			expiration = ""
		percentused = value_from_header(data, 'percentused')
		if percentused == "Error":
			percentused = ""
		product_id = value_from_header(data, 'id')
		addit_arr = [expiration, percentused]
		result = update_inventory_item(addit_arr, product_id, sessionkey)
	if command == "updategroup":
		groupid = value_from_header(data, 'groupid')
		barcode = value_from_header(data, 'barcode')
		sessionkey = value_from_header(data, 'sessionkey')
		result = update_group_of_item(groupid, barcode, sessionkey)
	if command == "test":
		result = "success"
	if command == "manualadd":
		barcode = value_from_header(data, 'barcode')
		name = value_from_header(data, 'name')
		des = value_from_header(data, 'description')
		man = value_from_header(data, 'manufacturer')
		amount = value_from_header(data, 'amount')
		gid = value_from_header(data, 'group')
		exper_date = value_from_header(data, 'expiration')
		session_key = value_from_header(data, 'sessionkey')
		if gid == "na":
			gid = ""
		if exper_date == "na":
			exper_date = ""
		result = add_new_item_man(barcode, name, des, man, amount, gid, exper_date, session_key)
	if command == "addrecipe":
		session_key = value_from_header(data, 'sessionkey')
		name = value_from_header(data, 'name')
		des = value_from_header(data, 'description')
		preptime = value_from_header(data, 'preptime')
		if preptime == "Error":
			preptime = -1
		cooktime = value_from_header(data, 'cooktime')
		if cooktime == "Error":
                        cooktime = -1
		image = ''
		ingredients = []
		recipe = [name,des,ingredients,image,int(preptime),int(cooktime)]
		kwlog.log(str(recipe))
		result = add_recipe(session_key, recipe)

	if command == "addshoppinglist":
		session_key = value_from_header(data, 'sessionkey')
		name = value_from_header(data, 'name')
		result = create_new_list(name, session_key)

	if command == "getshoppinglists":
		session_key = value_from_header(data, 'sessionkey')
		result = replace_commas_with_semicolons(get_shopping_lists(session_key))
		result = result[1:-1]
		kwlog.log(result)

	if command == "addshoppinglistitem":
		sessionkey = value_from_header(data, 'sessionkey')
		groupid = value_from_header(data, 'groupid')
		quantity = value_from_header(data, 'quantity')
		listid = value_from_header(data, 'listid')
		result =  add_item_to_list(groupid, quantity, listid, sessionkey)

	if command == "removeshoppinglistitem":
		listid = value_from_header(data, 'listid')
		sessionkey = value_from_header(data, 'sessionkey')
		groupid = value_from_header(data, 'groupid')
		result = remove_item_from_list(listid, groupid, sessionkey)
	if command == "clearshoppinglist":
		sessionkey = value_from_header(data, 'sessionkey')
		listid = value_from_header(data, 'listid')
		result = remove_all_items_from_list(listid, sessionkey)

	if command == "sendshoppinglist":
		sessionkey = value_from_header(data, 'sessionkey')
		listid = value_from_header(data, 'listid')
		result = send_list(listid, sessionkey)

	if command == "getshoppinglistid":
		sessionkey = value_from_header(data, 'sessionkey')
		result = get_list_ID(sessionkey)

	if command == "getgroupid":
		name = value_from_header(data, 'name')
		result = get_group_id(name)

	kwlog.log("Result: " + str(result))
	send(result, connection)
	kwlog.log("Result sent")
	connection.close()
	kwlog.log("Connection closing")
	return
예제 #6
0
파일: manager.py 프로젝트: mr7657/Backend
def service_request(data, connection):
    result = None
    command = value_from_header(data, 'command')
    if command == "Error":
        print(str(data))
        connection.close()
        return
    if command == 'register':
        username = value_from_header(data, 'username')
        fname = value_from_header(data, 'fname')
        lname = value_from_header(data, 'lname')
        email = value_from_header(data, 'email')
        password = value_from_header(data, 'password')
        result = add_new_user(username, fname, lname, email,
                              password.encode("utf-8"))

    if command == "activate":
        code = value_from_header(data, "code")
        result = update_account_activation_stats(code)

    if command == "login":
        username = value_from_header(data, 'username')
        password = value_from_header(data, 'password')
        kwlog.log(str(username + ":" + password))
        result = login_to_account(username, password.encode("utf-8"))

    if command == "updateaccount":
        sessionkey = value_from_header(data, 'sessionkey')
        fname = value_from_header(data, 'fname')
        lname = value_from_header(data, 'lname')
        email = value_from_header(data, 'email')
        password = value_from_header(data, 'password')
        if fname == "Error":
            fname = ''
        if lname == "Error":
            lname = ''
        if email == "Error":
            email = ''
        if password == "Error":
            password = ''
        result = update_account_information(fname, lname, email,
                                            password.encode("utf-8"),
                                            sessionkey)
    if command == "additem":
        barcode = value_from_header(data, 'barcode')
        sessionkey = value_from_header(data, 'sessionkey')
        result = replace_commas_with_semicolons(
            add_new_item(barcode, sessionkey))
    if command == "getitems":
        sessionkey = value_from_header(data, 'sessionkey')
        result = get_item_list(sessionkey)
        result = replace_commas_with_semicolons(result)

    if command == "removeitem":
        product_id = value_from_header(data, 'id')
        sessionkey = value_from_header(data, 'sessionkey')
        result = remove_item(product_id, sessionkey)

    if command == "getrecipes":
        sessionkey = value_from_header(data, 'sessionkey')
        result = replace_commas_with_semicolons(
            get_list_of_recipes(sessionkey))

    if command == "getingredients":
        sessionkey = value_from_header(data, 'sessionkey')
        recipeid = value_from_header(data, 'recipeid')
        result = get_list_of_ingredients(sessionkey, recipeid)
    if command == "removerecipe":
        recipe_id = value_from_header(data, 'recipeid')
        sessionkey = value_from_header(data, 'sessionkey')
        result = remove_recipe(recipe_id, sessionkey)

    if command == "updaterecipe":
        sessionkey = value_from_header(data, 'sessionkey')
        name = value_from_header(data, 'name')
        recipeid = value_from_header(data, 'recipeid')
        description = value_from_header(data, 'description')
        image = ''
        preptime = value_from_header(data, 'preptime')
        cooktime = value_from_header(data, 'cooktime')
        itemaction = value_from_header(data, 'itemaction')
        groupid = value_from_header(data, 'groupid')
        quantity = value_from_header(data, 'quantity')

        if sessionkey == "Error":
            sessionkey = ""
        if name == "Error":
            name = ""
        if recipeid == "Error":
            recipeid = ""
        if description == "Error":
            description = ""
        if preptime == "Error":
            preptime = ""
        if cooktime == "Error":
            cooktime = ""
        if itemaction == "Error":
            itemaction = ""
        if groupid == "Error":
            groupid = ""
        if quantity == "Error":
            quantity = ""

        item = []
        if groupid != "":
            item = [[groupid, quantity]]
        result = update_recipe(recipeid, name, description, image, preptime,
                               cooktime, item, itemaction, sessionkey)
    if command == "getgrouplist":
        result = replace_commas_with_semicolons_for_groups(
            get_list_of_generic_items())

    if command == "updateitem":
        sessionkey = value_from_header(data, 'sessionkey')
        expiration = value_from_header(data, 'expiration')
        if expiration == "Error":
            expiration = ""
        percentused = value_from_header(data, 'percentused')
        if percentused == "Error":
            percentused = ""
        product_id = value_from_header(data, 'id')
        addit_arr = [expiration, percentused]
        result = update_inventory_item(addit_arr, product_id, sessionkey)
    if command == "updategroup":
        groupid = value_from_header(data, 'groupid')
        barcode = value_from_header(data, 'barcode')
        sessionkey = value_from_header(data, 'sessionkey')
        result = update_group_of_item(groupid, barcode, sessionkey)
    if command == "test":
        result = "success"
    if command == "manualadd":
        barcode = value_from_header(data, 'barcode')
        name = value_from_header(data, 'name')
        des = value_from_header(data, 'description')
        man = value_from_header(data, 'manufacturer')
        amount = value_from_header(data, 'amount')
        gid = value_from_header(data, 'group')
        exper_date = value_from_header(data, 'expiration')
        session_key = value_from_header(data, 'sessionkey')
        if gid == "na":
            gid = ""
        if exper_date == "na":
            exper_date = ""
        result = add_new_item_man(barcode, name, des, man, amount, gid,
                                  exper_date, session_key)
    if command == "addrecipe":
        session_key = value_from_header(data, 'sessionkey')
        name = value_from_header(data, 'name')
        des = value_from_header(data, 'description')
        preptime = value_from_header(data, 'preptime')
        if preptime == "Error":
            preptime = -1
        cooktime = value_from_header(data, 'cooktime')
        if cooktime == "Error":
            cooktime = -1
        image = ''
        ingredients = []
        recipe = [name, des, ingredients, image, int(preptime), int(cooktime)]
        kwlog.log(str(recipe))
        result = add_recipe(session_key, recipe)

    if command == "addshoppinglist":
        session_key = value_from_header(data, 'sessionkey')
        name = value_from_header(data, 'name')
        result = create_new_list(name, session_key)

    if command == "getshoppinglists":
        session_key = value_from_header(data, 'sessionkey')
        result = replace_commas_with_semicolons(
            get_shopping_lists(session_key))
        result = result[1:-1]
        kwlog.log(result)

    if command == "addshoppinglistitem":
        sessionkey = value_from_header(data, 'sessionkey')
        groupid = value_from_header(data, 'groupid')
        quantity = value_from_header(data, 'quantity')
        listid = value_from_header(data, 'listid')
        result = add_item_to_list(groupid, quantity, listid, sessionkey)

    if command == "removeshoppinglistitem":
        listid = value_from_header(data, 'listid')
        sessionkey = value_from_header(data, 'sessionkey')
        groupid = value_from_header(data, 'groupid')
        result = remove_item_from_list(listid, groupid, sessionkey)
    if command == "clearshoppinglist":
        sessionkey = value_from_header(data, 'sessionkey')
        listid = value_from_header(data, 'listid')
        result = remove_all_items_from_list(listid, sessionkey)

    if command == "sendshoppinglist":
        sessionkey = value_from_header(data, 'sessionkey')
        listid = value_from_header(data, 'listid')
        result = send_list(listid, sessionkey)

    if command == "getshoppinglistid":
        sessionkey = value_from_header(data, 'sessionkey')
        result = get_list_ID(sessionkey)

    if command == "getgroupid":
        name = value_from_header(data, 'name')
        result = get_group_id(name)

    kwlog.log("Result: " + str(result))
    send(result, connection)
    kwlog.log("Result sent")
    connection.close()
    kwlog.log("Connection closing")
    return