Example #1
0
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"
Example #2
0
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
Example #3
0
def add_system_manager(system_manager):
    if system_manager.username == 'System':
        return False
    if RegisteredUsers.get_user(
            system_manager.username) is False and Shops.search_shop(
                system_manager.username) is False:
        return SystemManagers.add_system_manager(system_manager)
Example #4
0
def send_message_from_shop(username, message):
    output = False
    manager = StoreManagers.get_store_manager(username, message.from_username)
    if Shops.search_shop(
            message.to_username) is False and RegisteredUsers.is_user_exists(
                message.to_username) is False:
        return "FAILED: Target does not exists"
    if manager is not False:
        if manager.permission_reply_messages > 0:
            output = Messages.send_message_from_shop(message)
        else:
            return "FAILED: You don't have the permissions"
    if Owners.get_owner(username, message.from_username) is not False:
        output = Messages.send_message_from_shop(message)
    else:
        return "FAILED: You are not authorized"
    if output:
        users = [message.to_username]
        if message.to_username == 'System':
            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 <strong>Shop</strong>' +
            message.from_username + '</a>')
        return "SUCCESS"
    else:
        return "FAILED"
Example #5
0
def close_shop_permanently(username, shop_name):
    if username is not None and shop_name is not None:
        sys_manager = SystemManagers.is_system_manager(username)
        if sys_manager is not False:
            shop = search_shop(shop_name)
            if shop is not False:
                return Shops.close_shop_permanently(shop_name)
        return False
    return False
Example #6
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"
Example #7
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"
Example #8
0
def login(user):
    if SystemManagers.login(user.username,
                            hashlib.sha256(
                                user.password.encode()).hexdigest()):
        LoggerLogic.add_login_log(user.username)
        return "SUCCESS"
    if user.username is not None and user.password is not None:
        if RegisteredUsers.is_user_exists(user.username):
            user.password = hashlib.sha256(user.password.encode()).hexdigest()
            if RegisteredUsers.login(user):
                LoggerLogic.add_login_log(user.username)
                return "SUCCESS"
            return "FAILED:Password in incorrect"
        return "FAILED: Username is incorrect"
    return "FAILED: Missing Parameters"
Example #9
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"
Example #10
0
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'
Example #11
0
def is_system_manager(username):
    return SystemManagers.is_system_manager(username)
Example #12
0
def get_all_purchased_items(username):
    sys_manager = SystemManagers.is_system_manager(username)
    if sys_manager is not False:
        return PurchasedItems.get_all_purchased_items()
    return False
Example #13
0
def is_system_manager(username, password):
    return SystemManagers.login(username, password)