Skip to content

Commit

Permalink
Improve wording around CLI authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
ku1ik committed Feb 18, 2024
1 parent 0f53888 commit 50c9471
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions lib/asciinema_web/controllers/api_token_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions test/controllers/api_token_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 50c9471

Please sign in to comment.