コード例 #1
0
def update_shopping_policy_on_shop(username, policy_id, field_name, new_value, shop_name):
    if policy_id is not None and field_name is not None and new_value is not None:
        if int(policy_id) < 0:
            return "FAILED: Invalid id of Policy"
        if field_name not in ['shop_name', 'conditions', 'restriction', 'quantity']:
            return "FAILED: Invalid field name"
        if Owners.get_owner(username, shop_name) is not False:
            if field_name in ['conditions']:
                status = checkConditionsSyntax(new_value)
                if new_value == "":
                    new_value = "1=1"
                if status is not True:
                    return status

            if not ShoppingPolicies.update_shopping_policy_on_shop(policy_id, field_name, new_value):
                return "FAILED: DB error."
            LoggerLogic.add_event_log(username, "POLICY: UPDATE SHOP SHOPPING POLICY")
            return True
        manager = StoreManagers.get_store_manager(username, shop_name)
        if manager is not False:
            if manager.permission_set_policy > 0:
                if field_name in ['conditions']:
                    status = checkConditionsSyntax(new_value)
                    if new_value == "":
                        new_value = "1=1"
                    if status is not True:
                        return status

                if not ShoppingPolicies.update_shopping_policy_on_shop(policy_id, field_name, new_value):
                    return "FAILED: DB error."
                LoggerLogic.add_event_log(username, "POLICY: UPDATE SHOP SHOPPING POLICY")
                return True
            return 'FAILED: no permissions!'
        return 'FAILED: you are not a the Owner of the shop'
    return "FAILED: One (or more) of the parameters is None"
コード例 #2
0
ファイル: UsersLogic.py プロジェクト: omriattiya/uTrade
def remove_user(username, registered_user):
    if username is not None and registered_user is not None:
        if SystemManagers.is_system_manager(username) is not False:
            sys_manager = SystemManagers.is_system_manager(
                registered_user.username)
            is_store_manager = StoreManagers.is_store_manager(
                registered_user.username)
            is_owner = Owners.is_owner(registered_user.username)
            if sys_manager is False:
                user = RegisteredUsers.get_user(registered_user.username)
                if user is not False:
                    result_delete = True
                    if is_store_manager is not False:
                        result_delete = StoreManagers.remove_manager(
                            registered_user.username)
                    else:
                        if is_owner is not False:
                            result_delete = Owners.remove_owner(
                                registered_user.username)
                    final_result = result_delete and RegisteredUsers.remove_user(
                        registered_user.username)
                    if final_result:
                        LoggerLogic.add_event_log(username, "DELETE USER")
                    return final_result
            return False
    return False
コード例 #3
0
ファイル: MessagingLogic.py プロジェクト: omriattiya/uTrade
def send_message(message):
    if message.from_username is not None and message.to_username is not None and message.content is not None:
        if message.to_username == 'System' or get_user(
                message.to_username) is not False or Shops.search_shop(
                    message.to_username) is not False:
            # output = Messages.send_message(message)

            if SystemManagers.is_system_manager(message.from_username):
                message.from_username = '******'
            output = Messages.send_message(message)
        else:
            return "FAILED: Target user is incorrect"
    else:
        return "FAILED: Missing Parameters"
    if output:
        users = [message.to_username]
        if message.to_username == 'System':
            LoggerLogic.add_event_log(message.from_username,
                                      "REPORT ITEM / SHOP")
            SMs = SystemManagers.get_all_system_managers()
            SM_names = []
            for sm in SMs:
                SM_names.append(sm.username)
            users = SM_names
        MessagingAlerts.notify_messaging_alerts(
            users, '<a href = "../app/home/messages/?content=received" > '
            'You Have a new message from ' + message.from_username + '</a>')
        return "SUCCESS"
    else:
        return "FAILED"
コード例 #4
0
def remove_shopping_policy_on_category(username, policy_id):
    if policy_id is not None and policy_id > 0:
        if SystemManagers.is_system_manager(username) is not False:
            if not ShoppingPolicies.remove_shopping_policy_on_category(policy_id):
                return "FAILED: DB error."
            LoggerLogic.add_event_log(username, "POLICY: REMOVE CATEGORY SHOPPING POLICY")
            return True
        return 'FAILED: you are not a System Manager'
    return "FAILED: Invalid id of Policy"
コード例 #5
0
def remove_shopping_policy_on_shop(username, policy_id, shop_name):
    if policy_id is not None and policy_id > 0:
        if Owners.get_owner(username, shop_name) is not False:
            if not ShoppingPolicies.remove_shopping_policy_on_shop(policy_id):
                return "FAILED: DB error."
            LoggerLogic.add_event_log(username, "POLICY: REMOVE SHOP SHOPPING POLICY")
            return True
        return 'FAILED: you are not a the Owner of the shop'
    return "FAILED: Invalid id of Policy"
コード例 #6
0
ファイル: UsersLogic.py プロジェクト: omriattiya/uTrade
def re_open_shop(username, shop_name):
    owner_of_shop = Owners.get_owner(username, shop_name)
    if owner_of_shop is not False:
        result = Shops.re_open_shop(shop_name)
        if result:
            LoggerLogic.add_event_log(username,
                                      "SHOP STATUS CHANGED - RE-OPEN")
        return result
    else:
        return False
コード例 #7
0
ファイル: ShopLogic.py プロジェクト: omriattiya/uTrade
def create_shop(shop, username):
    if shop is not None and username is not None:
        if Shops.search_shop(shop.name) is False:
            if Shops.create_shop(shop):
                if Owners.add_owner(Owner(username, shop.name, None)):
                    LoggerLogic.add_event_log(username, "OPEN SHOP")
                    return "SUCCESS"
                return "FAILED: Adding Owner"
            return "FAILED: Adding Shop"
        return "FAILED: Shop name is taken"
    return "FAILED: Missing parameters"
コード例 #8
0
ファイル: LoggerTests.py プロジェクト: omriattiya/uTrade
 def test_get_all_events(self):
     LoggerLogic.add_event_log("omri", "open shop")
     LoggerLogic.add_event_log("omri2", "payAll")
     logs = Logger.get_all_event_logs()
     self.assertTrue(len(logs) == 2)
     event_log = logs[1]
     self.assertEqual(event_log.username, "omri")
     self.assertEqual(event_log.event, "open shop")
     event_log = logs[0]
     self.assertEqual(event_log.username, "omri2")
     self.assertEqual(event_log.event, "payAll")
コード例 #9
0
ファイル: UsersLogic.py プロジェクト: omriattiya/uTrade
def close_shop(username, shop_name):
    owner_of_shop = Owners.get_owner(username, shop_name)
    if owner_of_shop is not False:
        result = Shops.close_shop(shop_name)
        if result:
            lotteries = get_lotteries_by_shop(shop_name)
            for lottery in lotteries:
                lottery_timer(lottery.id)
            LoggerLogic.add_event_log(username, "SHOP STATUS CHANGED - CLOSE")
        return result
    else:
        return False
コード例 #10
0
def add_shopping_policy_on_identity(username, conditions, restriction, quantity):
    if conditions is not None and restriction is not None and quantity is not None:
        if restriction not in ['N', 'AL', 'E', 'UT']:
            return "FAILED: Invalid value of restriction."
        if int(quantity) < 0:
            return "FAILED: Negative quantity is invalid."
        if SystemManagers.is_system_manager(username) is not False:
            if not ShoppingPolicies.add_shopping_policy_on_identity(conditions, restriction, quantity):
                return "FAILED: DB error."
            LoggerLogic.add_event_log(username, "POLICY: ADD IDENTITY SHOPPING POLICY")
            return True
        return 'FAILED: you are not a System Manager'
    return "FAILED: One (or more) of the parameters is None"
コード例 #11
0
def pay_all_guest(guest):
    if guest is not None:
        #  check if cart has items
        empty = check_empty_cart_guest(guest)
        if empty is not True:
            purchase_id = 0
            #  if so, check foreach item if the requested amount exist
            cart_items = Consumer.guestShoppingCart[guest]
            # cart_items is a array consist of shopping_cart objects
            shopping_policy_status = UserShoppingCartLogic.shopping_policy_check(
                "guest", cart_items)
            if shopping_policy_status is not True:
                return shopping_policy_status
            message = check_stock_for_shopping_cart(cart_items)
            if message is not True:
                return message
            # if so, sum all items costs, get from costumer his credentials
            total_cost = 0
            # for each item, calculate visible_discount
            for shopping_cart_item in cart_items:
                item = get_item(shopping_cart_item.item_id)
                new_price = UserShoppingCartLogic.get_new_price_for_item(
                    item, shopping_cart_item)
                total_cost = total_cost + shopping_cart_item.item_quantity * new_price
                new_quantity = item.quantity - shopping_cart_item.item_quantity
                status = ItemsLogic.update_stock(item.id, new_quantity)
                if status is False:
                    return 'Something went wrong with the purchase'
                # live alerts
                owners = Owners.get_owners_by_shop(item.shop_name)
                owners_name = []
                for owner in owners:
                    owners_name.append(owner.username)
                PurchasesAlerts.notify_purchasing_alerts(
                    owners_name, '<strong>' + guest +
                    '</strong> has bought item <a href="http://localhost:8000/app/item/?item_id='
                    + str(item.id) + '"># <strong>' + str(item.id) +
                    '</strong></a> from your shop')
            pay_confirmation = ExternalSystems.payment.pay(total_cost, guest)
            if pay_confirmation is False:
                return 'Payment System Denied.'
            sup_confirmation = ExternalSystems.supply.supply_a_purchase(
                guest, purchase_id)
            if sup_confirmation is False:
                return 'Supply System Denied.'
            status = remove_shopping_cart_guest(guest)
            if status is False:
                return 'Something went wrong with the purchase'
            LoggerLogic.add_event_log("GUEST", "PAY ALL")
            return [purchase_id, total_cost]
    return 'Shopping cart is empty'
コード例 #12
0
ファイル: LoggerTests.py プロジェクト: omriattiya/uTrade
 def test_add_event(self):
     self.assertTrue(LoggerLogic.add_event_log("omri", "open shop"))
     logs = Logger.get_all_event_logs()
     self.assertTrue(len(logs) == 1)
     event_log = logs[0]
     self.assertEqual(event_log.username, "omri")
     self.assertEqual(event_log.event, "open shop")
コード例 #13
0
def update_shopping_policy_on_category(username, policy_id, field_name, new_value):
    if policy_id is not None and field_name is not None and new_value is not None:
        if int(policy_id) < 0:
            return "FAILED: Invalid id of Policy"
        if field_name not in ['category', 'conditions', 'restriction', 'quantity']:
            return "FAILED: Invalid field name"
        if SystemManagers.is_system_manager(username) is not False:
            if field_name in ['conditions']:
                status = checkConditionsSyntax(new_value)
                if new_value == "":
                    new_value = "1=1"
                if status is not True:
                    return status

            if not ShoppingPolicies.update_shopping_policy_on_category(policy_id, field_name, new_value):
                return "FAILED: DB error."
            LoggerLogic.add_event_log(username, "POLICY: UPDATE CATEGORY SHOPPING POLICY")
            return True
        return 'FAILED: you are not a System Manager'
    return "FAILED: One (or more) of the parameters is None"
コード例 #14
0
ファイル: UsersLogic.py プロジェクト: omriattiya/uTrade
def register(user):
    if user.username is not None and user.password is not None and not SystemManagers.is_system_manager(
            user.username):
        if re.match(r'[A-Za-z0-9]{8,20}', user.username):
            if re.match(r'[A-Za-z0-9]{8,20}', user.password):
                user.password = hashlib.sha256(
                    user.password.encode()).hexdigest()
                if Shops.search_shop(user.username) is not False:
                    return 'FAILED: Username is already taken'
                if RegisteredUsers.get_user(user.username) is not False:
                    return 'FAILED: Username is already taken'
                if RegisteredUsers.add_user(user):
                    UserDetails.insert(user.username)
                    LoggerLogic.add_event_log(user.username, "REGISTER")
                    return 'SUCCESS'
                return 'FAILED'
            else:
                return 'FAILED: Password must be 8 to 20 alphabetic letters and numbers'
        else:
            return 'FAILED: Username must be 8 to 20 alphabetic letters and numbers'
    else:
        return 'FAILED: Username is already taken'
コード例 #15
0
def add_shopping_policy_on_shop(username, shop_name, conditions, restriction, quantity):
    if shop_name is not None and conditions is not None:
        if restriction is not None and quantity is not None:
            if restriction not in ['N', 'AL', 'E', 'UT']:
                return "FAILED: Invalid value of restriction."
            if int(quantity) < 0:
                return "FAILED: Negative quantity is invalid."
            if Owners.get_owner(username, shop_name) is not False:
                if not ShoppingPolicies.add_shopping_policy_on_shop(shop_name, conditions, restriction, quantity):
                    return "FAILED: DB error."
                LoggerLogic.add_event_log(username, "POLICY: ADD SHOP SHOPPING POLICY")
                return True
            manager = StoreManagers.get_store_manager(username,shop_name)
            if manager is not False:
                if manager.permission_set_policy > 0:
                    if not ShoppingPolicies.add_shopping_policy_on_shop(shop_name, conditions, restriction, quantity):
                        return "FAILED: DB error."
                    LoggerLogic.add_event_log(username, "POLICY: ADD SHOP SHOPPING POLICY")
                    return True
                return 'FAILED: no permissions!'
            return 'FAILED: you are not a the Owner of the shop'
        return "FAILED: One (or more) of the parameters is None"
    return "FAILED: One (or more) of the parameters is None"
コード例 #16
0
def pay_all(login_token):
    lotteries = []
    if login_token is not None:
        #  check if cart has items
        empty = check_empty_cart_user(login_token)
        if empty is not True:
            username = Consumer.loggedInUsers[login_token]
            #  if so, check foreach item if the requested amount exist
            cart_items = get_cart_items(login_token)

            shopping_policy_status = shopping_policy_check(username, cart_items)
            if shopping_policy_status is not True:
                return shopping_policy_status

            # cart_items is a array consist of shopping_cart objects
            message = check_stock_for_shopping_cart(cart_items)
            if message is not True:
                return message
            # if so, sum all items costs, get from costumer his credentials
            total_cost = 0
            # for each item, calculate visible_discount
            purchase_id = Purchases.add_purchase_and_return_id(datetime.now(), username, 0)
            if purchase_id is False:
                return 'Something went wrong with the purchase'
            for shopping_cart_item in cart_items:
                item = get_item(shopping_cart_item.item_id)
                new_price = get_new_price_for_item(item, shopping_cart_item)
                lottery_message = check_lottery_ticket(item, shopping_cart_item, username)
                if lottery_message is not True:
                    return lottery_message
                total_cost = total_cost + shopping_cart_item.item_quantity * new_price
                status = PurchasedItems.add_purchased_item(purchase_id, shopping_cart_item.item_id,
                                                           shopping_cart_item.item_quantity,
                                                           shopping_cart_item.item_quantity * new_price)
                if status is False:
                    return 'Something went wrong with the purchase'
                status = update_purchase_total_price(purchase_id, total_cost)
                if status is False:
                    return 'Something went wrong with the purchase'
                new_quantity = item.quantity - shopping_cart_item.item_quantity
                if item.kind == 'ticket':
                    if new_quantity == 0:
                        lotteries.append(item.id)
                status = ItemsLogic.update_stock(item.id, new_quantity)
                if status is False:
                    return 'Something went wrong with the purchase'
                # live alerts
                owners = Owners.get_owners_by_shop(item.shop_name)
                owners_name = []
                for owner in owners:
                    if owner.should_notify > 0:
                        owners_name.append(owner.username)
                PurchasesAlerts.notify_purchasing_alerts(owners_name,
                                                         '<strong>' + username + '</strong> has bought item <a href="http://localhost:8000/app/item/?item_id=' + str(
                                                             item.id) + '"># <strong>' + str(
                                                             item.id) + '</strong></a> from your shop')
            pay_confirmation = ExternalSystems.payment.pay(total_cost, username)
            if pay_confirmation is False:
                return 'Payment System Denied.'
            sup_confirmation = ExternalSystems.supply.supply_a_purchase(username, purchase_id)
            if sup_confirmation is False:
                return 'Supply System Denied.'
            remove_shopping_cart(login_token)
            status = ShoppingCartDB.remove_shopping_cart(username)
            lottery_ending_check(lotteries)
            if status:
                LoggerLogic.add_event_log(username, "PAY ALL")
                return [purchase_id, total_cost]
    return 'Shopping cart is empty'