 
   def create(conn, %{"input" => %{"csv_data" => csv_data, "target" => target, "title" => title}}) do
     case bulk_target_handler(csv_data, target) do
-      {:ok, _entities} ->
+      {:ok, created_entities} ->
+        post_creation(conn, created_entities, target)
         conn
         |> put_flash(:info, "All users are created and notified by.")
         |> redirect(to: user_path(conn, :index))

  @moduledoc false
  use CoursePlannerWeb, :controller
  alias CoursePlanner.BulkHelper

  import Canary.Plugs
  plug :authorize_controller

      _      -> {:error, "", :illegal_operation, ""}
    end
  end

  defp post_creation(conn, created_entities, target) do
    case target do
      "user" ->
        created_entities
        |> Enum.reduce(%{}, fn({_operation_id, user}, _out) ->
            url = Helpers.password_url(conn, :edit, user.reset_password_token)
            ControllerHelpers.send_user_email(:welcome, user, url)
          end)
        {:ok, created_entities}
      _  -> {:ok, :ok}
    end
  end
end
