def test_torture1(self): # Adding Users status = UsersLogic.register(RegisteredUser('user1user1', 'asdas12da')) self.assertTrue(status) status = UsersLogic.register(RegisteredUser('user2user2', 'cse12fdsf')) self.assertTrue(status) status = UsersLogic.register(RegisteredUser('user3user3', '12312124')) self.assertTrue(status) status = UsersLogic.register(RegisteredUser('user4user4', '1344321324')) self.assertTrue(status) status = UsersLogic.register(RegisteredUser('user5user5', '1c24c143c1')) self.assertTrue(status) # Adding System Managers status = UsersLogic.add_system_manager( SystemManager('sys1sys1', 'POWER123')) self.assertTrue(status) status = UsersLogic.edit_password( RegisteredUser('user5user5', '12312456')) self.assertTrue(status) user = RegisteredUsers.get_user('user5user5') UsersLogic.remove_user('sys1sys1', user) status = RegisteredUsers.get_user('user5user5') self.assertFalse(status)
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
def edit_password(user): if user.username == 'System': return "FAILED: System Can't changed password" status = RegisteredUsers.get_user(user.username) if status and user.username is not None and user.password is not None: if re.match(r'[A-Za-z0-9]{8,20}', user.password): user.password = hashlib.sha256(user.password.encode()).hexdigest() if RegisteredUsers.edit_user_password(user): return 'SUCCESS' return 'FAILED' return 'FAILED: Password must be 8 to 20 alphabetic letters and numbers' return "FAILED: username not exists"
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"
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)
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"
def add_owner(username, owner): if username is not None: if Owners.get_owner(username, owner.shop_name) is not False: if RegisteredUsers.get_user(owner.username) is not False: if Owners.get_owner(owner.username, owner.shop_name) is not False: to_return = 'FAILED! ' + owner.username + ' is already an owner' return to_return result = Owners.add_owner(owner) if result: result = HistoryAppointings.add_history_appointing( username, owner.username, 'Owner', owner.shop_name, strftime("%d-%m-%Y %H:%M:%S", gmtime()), 'Owner') else: return "FAILED" if result and is_manager_of_shop(owner.username, owner.shop_name): result = remove_store_manager(username, owner.shop_name, owner.username) if result: return "SUCCESS" else: return "FAILED" elif result: return "SUCCESS" else: return "FAILED" else: return "FAILED: Username does not exists" else: return "FAILED: You are not the owner of this shop" else: return "FAILED: Missing Parameters"
def update_code_shopping_cart(username, item_id, code): if username is not None and item_id is not None and code is not None: user = RegisteredUsers.get_user(username) if user is not False: if len(code) == 15 and isinstance(code, str): return ShoppingCartDB.update_code_shopping_cart( username, item_id, code) return False
def update_item_shopping_cart(username, item_id, new_quantity): if username is not None and item_id is not None and new_quantity >= 0: if new_quantity is 0: return remove_item_shopping_cart(username, item_id) if ItemsLogic.check_in_stock(item_id, new_quantity) is False: return False user = RegisteredUsers.get_user(username) if user is not False: return ShoppingCartDB.update_item_shopping_cart( username, item_id, new_quantity) return False
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'
def shopping_policy_check(username, cart_items): if username is not "guest": user = RegisteredUsers.get_user(username) if user is False: return "FAILED: User does not exist" id_status = check_identity_shopping_policies(username, cart_items) if id_status is not True: return id_status items_status = check_items_shopping_policies(username, cart_items) if items_status is not True: return items_status category_status = check_category_shopping_policies(username, cart_items) if category_status is not True: return category_status shop_status = check_shop_shopping_policies(username, cart_items) if shop_status is not True: return shop_status return True
def add_or_update_lottery_customer(purchased_item, username, price, number_of_tickets): if purchased_item is not None and username is not None and price is not None and price >= 0: lottery_customer = Lotteries.get_lottery_customer( purchased_item, username) user = RegisteredUsers.get_user(username) if user is not False: lottery = Lotteries.get_lottery(purchased_item) if lottery is not False: if lottery_customer is not False: return Lotteries.update_lottery_item( purchased_item, username, price, number_of_tickets) else: return Lotteries.add_lottery_item(purchased_item, username, price, number_of_tickets) else: print("No such lottery") else: print("No such user") return False
def update_item_shopping_cart(login_token, item_id, new_quantity): if login_token is not None and item_id is not None and new_quantity >= 0: username = Consumer.loggedInUsers[login_token] shopping_cart = Consumer.loggedInUsersShoppingCart[login_token] if new_quantity is 0: return remove_item_shopping_cart(username, item_id) if ItemsLogic.check_in_stock(item_id, new_quantity) is False: return False user = RegisteredUsers.get_user(username) if user is not False: i = 0 while i < len(shopping_cart): if shopping_cart[i].item_id == item_id: if new_quantity == 0: shopping_cart.remove(shopping_cart[i]) return True else: shopping_cart[i].item_quantity = new_quantity return True i = i + 1 return False
def add_manager(username, store_manager): if username is not None: if Owners.get_owner(username, store_manager.store_name) is not False: if RegisteredUsers.get_user(store_manager.username) is not False: if store_manager.store_name is not None: if Owners.get_owner(store_manager.username, store_manager.store_name): return "FAILED! An owner can't be store manager" if StoreManagers.add_manager(store_manager): if HistoryAppointings.add_history_appointing( username, store_manager.username, 'Store Manager', store_manager.store_name, strftime("%d-%m-%Y %H:%M:%S", gmtime()), ''): return 'SUCCESS' return "FAILED" return "FAILED" else: return "FAILED: Shop does not exists" else: return "FAILED: User does not exists" else: return "FAILED: You are not the owner of this shop" else: return "FAILED: Missing Parameters"
def remove_item_shopping_cart(username, item_id): if username is not None and item_id is not None: user = RegisteredUsers.get_user(username) if user is not False: return ShoppingCartDB.remove_item_shopping_cart(username, item_id)
def get_all_users(): return RegisteredUsers.get_all_users()
def get_purchase_history(username): if username is not None: return RegisteredUsers.get_purchase_history(username)
def get_registered_user(username): return RegisteredUsers.get_user(username)