def demand_friend(self, content): ''' Manage the friend demand Content: target username ''' is_error = False # check target is not user if content == self.username: is_error = True # check requested user exist if not DataBase.is_user(content): is_error = True # check not already friends if content in DataBase.get_friends(self.username): is_error = True if is_error: # send error in friend demand self.send(Message('rdfr', False), pickling=True) return DataBase.add_friend_demand(content, self.username) # check if requested user is connected if Interaction.is_user(content): Interaction.send_demand_friend(content, self.username) # send friend demand is ok self.send(Message('rdfr', True), pickling=True)
def login(self, content): ''' Log the user in. Content: username, password ''' username, password = content # check that the username exists and that the password is correct if DataBase.is_user(username): if Interaction.is_user(username): # can't log in -> already connected self.send(Message('rlg', False), pickling=True) return if DataBase.get_password(username) == password: # log in self.send(Message('rlg', True), pickling=True) self._log_client(username) return # can't log in self.send(Message('rlg', False), pickling=True)