def find_user_by_name(self, username): """ Finds the user with username Args: username the name for the user. Returns: The User for that username. Raises: NoSuchUser if the user does not exist. """ row = self.user_query(username) if row is None: raise NoSuchUser return User.from_row(row)
def add_user(self, user): """ Ignores the ID attribute of user, allowing the database to create a new autoincrement ID. Use the returned User to make calls to find_* Args: user a User object containing the row data (except for the ID) Returns: A new User object with the ID field filled in. """ # Pass in null for the ID; sqlite will automatically generate an ID. self.cursor.execute( "insert into users values (null, :username, :hashed_password, :salt)", {"username": user.get_username(), "hashed_password": user.get_hashed_password(), "salt": user.get_salt()}, ) self.connection.commit() return User.from_row((self.cursor.lastrowid, user.get_username(), user.get_hashed_password(), user.get_salt()))