defmodule ToweropsWeb.UserSettingsController do
  @moduledoc """
  Controller for user settings operations that require traditional request/response handling.

  Most user settings functionality is now handled by UserSettingsLive.
  This controller only handles email confirmation via token.
  """
  use ToweropsWeb, :controller

  alias Towerops.Accounts

  def confirm_email(conn, %{"token" => token}) do
    case Accounts.update_user_email(conn.assigns.current_scope.user, token) do
      {:ok, _user} ->
        conn
        |> put_flash(:info, "Email changed successfully.")
        |> redirect(to: ~p"/users/settings")

      {:error, _} ->
        conn
        |> put_flash(:error, "Email change link is invalid or it has expired.")
        |> redirect(to: ~p"/users/settings")
    end
  end
end
