From 50c9471c2d44d9b2f403947412f995ee3486b615 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Sun, 18 Feb 2024 21:56:39 +0100 Subject: [PATCH] Improve wording around CLI authentication --- .../controllers/api_token_controller.ex | 16 ++++++++-------- test/controllers/api_token_controller_test.exs | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/asciinema_web/controllers/api_token_controller.ex b/lib/asciinema_web/controllers/api_token_controller.ex index f5129c56b..68f14fb9d 100644 --- a/lib/asciinema_web/controllers/api_token_controller.ex +++ b/lib/asciinema_web/controllers/api_token_controller.ex @@ -10,16 +10,16 @@ defmodule AsciinemaWeb.ApiTokenController do {:ok, api_token} -> conn |> maybe_merge_users(api_token.user) - |> redirect_to_profile + |> redirect_to_profile() {:error, :token_invalid} -> conn - |> put_flash(:error, "Invalid token. Make sure you pasted the URL correctly.") + |> put_flash(:error, "Invalid installation ID - make sure to paste the URL correctly") |> redirect(to: root_path()) {:error, :token_revoked} -> conn - |> put_flash(:error, "This token has been revoked.") + |> put_flash(:error, "This CLI authentication has been revoked") |> redirect(to: root_path()) end end @@ -29,8 +29,8 @@ defmodule AsciinemaWeb.ApiTokenController do Accounts.revoke_api_token!(api_token) conn - |> put_flash(:info, "Token revoked.") - |> redirect(to: Routes.user_path(conn, :edit)) + |> put_flash(:info, "CLI authentication revoked") + |> redirect(to: ~p"/user/edit") end defp maybe_merge_users(conn, api_token_user) do @@ -39,16 +39,16 @@ defmodule AsciinemaWeb.ApiTokenController do case {current_user, api_token_user} do # api token was just created {%User{id: id}, %User{id: id}} -> - put_flash(conn, :info, "Recorder token has been added to your account.") + put_flash(conn, :info, "CLI successfully authenticated with your account") # api token belongs to tmp user {%User{}, %User{email: nil, username: nil}} -> Asciinema.merge_accounts(api_token_user, current_user) - put_flash(conn, :info, "Recorder token has been added to your account.") + put_flash(conn, :info, "CLI successfully authenticated with your account") # api token belongs to other regular user {%User{}, %User{}} -> - put_flash(conn, :error, "This recorder token belongs to a different user.") + put_flash(conn, :error, "This CLI has been authenticated with a different user account") end end diff --git a/test/controllers/api_token_controller_test.exs b/test/controllers/api_token_controller_test.exs index 8bd8a69e0..a1fa76550 100644 --- a/test/controllers/api_token_controller_test.exs +++ b/test/controllers/api_token_controller_test.exs @@ -35,7 +35,7 @@ defmodule Asciinema.ApiTokenControllerTest do test "with invalid token", %{conn: conn} do conn = get(conn, "/connect/nopenope") assert redirected_to(conn, 302) == "/" - assert flash(conn, :error) =~ ~r/invalid token/i + assert flash(conn, :error) =~ ~r/invalid/i end test "with revoked token", %{conn: conn} do @@ -53,13 +53,13 @@ defmodule Asciinema.ApiTokenControllerTest do test "with his own token", %{conn: conn} do conn = get(conn, "/connect/#{@regular_user_token}") assert redirected_to(conn, 302) == "/~test" - assert flash(conn, :info) + assert flash(conn, :info) =~ ~r/successfully/ end test "regular user with other regular user token", %{conn: conn} do conn = get(conn, "/connect/#{@other_regular_user_token}") assert redirected_to(conn, 302) == "/~test" - assert flash(conn, :error) + assert flash(conn, :error) =~ ~r/different/ end defp login_as(conn, user) do