def new_for_user(cls, user_id): str_user_id = str(user_id) shard_id = MySQL.get_shard_id_for_string(str_user_id) id = MySQL.next_id(shard_id) secret = RandomToken.build(16) return cls(id, str_user_id, secret, user_id, True)
def generate_token(self): return RandomToken.build(self.TOKEN_LENGTH, self.user.id)