<commit_before>defmodule Api.UserController do
  use Api.Web, :controller

  alias Api.{Controller.Errors, SessionActions, SessionView, UserActions}

  plug :scrub_params, "user" when action in [:create, :update]
  plug Guardian.Plug.EnsureAuthenticated, [handler: Errors] when action in [:update, :delete]

  def index(conn, _params) do
    render(conn, "index.json", users: UserActions.all)
  end

  def show(conn, %{"id" => id}) do
    render(conn, "show.json", user: UserActions.get(id))
  end

  def create(conn, %{"user" => user_params}) do
    case UserActions.create(user_params) do
      {:ok, jwt, user} ->
        conn
        |> put_status(:created)
        |> put_resp_header("location", user_path(conn, :show, user))
        |> render(SessionView, "show.json", data: %{jwt: jwt, user: user})
      {:error, changeset} -> Errors.changeset(conn, changeset)
    end
  end

  def update(conn, %{"id" => id, "user" => user_params}) do
    case UserActions.update(SessionActions.current_user(conn), id, user_params) do
      {:ok, user} -> render(conn, "show.json", user: user)
      {:error, changeset} -> Errors.changeset(conn, changeset)
    end
  end

  def delete(conn, %{"id" => id}) do
    case UserActions.delete(SessionActions.current_user(conn), id) do
      :unauthorized -> Errors.unauthorized(conn, nil)
      _ -> send_resp(conn, :no_content, "")
    end
  end

  def get_token(conn, %{"email" => email}) do
    case UserActions.get_token(email) do
      {:error, changeset} -> Errors.changeset(conn, changeset)
      {:ok, _} -> send_resp(conn, :no_content, "")
      code -> Errors.build(conn, :not_found, code)
    end
  end

  def recover_password(conn, %{"token" => token, "password" => password}) do
    case UserActions.recover_password(token, password) do
      {:error, changeset} -> Errors.changeset(conn, changeset)
      {:ok, user} -> send_resp(conn, :no_content, "")
      code -> Errors.build(conn, :unprocessable_entity, code)
    end
  end
end
<commit_msg>Unused variable<commit_after>defmodule Api.UserController do
  use Api.Web, :controller

  alias Api.{Controller.Errors, SessionActions, SessionView, UserActions}

  plug :scrub_params, "user" when action in [:create, :update]
  plug Guardian.Plug.EnsureAuthenticated, [handler: Errors] when action in [:update, :delete]

  def index(conn, _params) do
    render(conn, "index.json", users: UserActions.all)
  end

  def show(conn, %{"id" => id}) do
    render(conn, "show.json", user: UserActions.get(id))
  end

  def create(conn, %{"user" => user_params}) do
    case UserActions.create(user_params) do
      {:ok, jwt, user} ->
        conn
        |> put_status(:created)
        |> put_resp_header("location", user_path(conn, :show, user))
        |> render(SessionView, "show.json", data: %{jwt: jwt, user: user})
      {:error, changeset} -> Errors.changeset(conn, changeset)
    end
  end

  def update(conn, %{"id" => id, "user" => user_params}) do
    case UserActions.update(SessionActions.current_user(conn), id, user_params) do
      {:ok, user} -> render(conn, "show.json", user: user)
      {:error, changeset} -> Errors.changeset(conn, changeset)
    end
  end

  def delete(conn, %{"id" => id}) do
    case UserActions.delete(SessionActions.current_user(conn), id) do
      :unauthorized -> Errors.unauthorized(conn, nil)
      _ -> send_resp(conn, :no_content, "")
    end
  end

  def get_token(conn, %{"email" => email}) do
    case UserActions.get_token(email) do
      {:error, changeset} -> Errors.changeset(conn, changeset)
      {:ok, _} -> send_resp(conn, :no_content, "")
      code -> Errors.build(conn, :not_found, code)
    end
  end

  def recover_password(conn, %{"token" => token, "password" => password}) do
    case UserActions.recover_password(token, password) do
      {:error, changeset} -> Errors.changeset(conn, changeset)
      {:ok, _} -> send_resp(conn, :no_content, "")
      code -> Errors.build(conn, :unprocessable_entity, code)
    end
  end
end

{'fraction_non_alphanumeric': 0.15241915266984207, 'fraction_numerical': 0.0, 'mean_word_length': 3.661214953271028, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 49, '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': '1668230', 'n_tokens_mistral': 1369, 'n_tokens_neox': 1346, 'n_words': 328}