<commit_before>defmodule EspiDni.AuthHandler do

  @moduledoc """
  Create or retreive the team and user from an auth request
  """
  alias Ueberauth.Auth
  alias EspiDni.TeamFromAuth
  alias EspiDni.UserFromAuth

  def init_from_auth(%Auth{} = auth) do
    with {:ok, team} <- TeamFromAuth.find_or_create(auth),
         {:ok, user} <- UserFromAuth.find_or_create(auth, team) do
      {:ok, team, user}
    end
    |> case do
        {:ok, team, user} -> {:ok, team, user}
        {:error, changeset} -> {:error, changeset}
      end
  end

end<commit_msg>Send welcome message once user and team are added<commit_after>defmodule EspiDni.AuthHandler do

  @moduledoc """
  Create or retreive the team and user from an auth request
  """
  alias Ueberauth.Auth
  alias EspiDni.TeamFromAuth
  alias EspiDni.UserFromAuth

  def init_from_auth(%Auth{} = auth) do
    with {:ok, team} <- TeamFromAuth.find_or_create(auth),
         {:ok, user} <- UserFromAuth.find_or_create(auth, team),
         {:ok, user} <- send_welcome_message(user) do
      {:ok, team, user}
    end
    |> case do
        {:ok, team, user} -> {:ok, team, user}
        {:error, changeset} -> {:error, changeset}
      end
  end

  defp send_welcome_message(user) do
    case EspiDni.SlackWeb.send_message(user, "<PASSWORD>") do
      %{"ok" => true } -> {:ok, user}
      %{"ok" => false } -> {:error, user}
    end
  end
end
{'fraction_non_alphanumeric': 0.13189964157706094, 'fraction_numerical': 0.0, 'mean_word_length': 2.9885714285714284, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2982480', 'n_tokens_mistral': 511, 'n_tokens_neox': 489, 'n_words': 133}