mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-10-10 13:38:09 +08:00
Improve authentication form feedback for the user (#1543)
This commit is contained in:
parent
b8997d6ce2
commit
2eb601d32a
2 changed files with 18 additions and 4 deletions
|
@ -15,8 +15,8 @@ defmodule LivebookWeb.AuthController do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def index(conn, _params) do
|
def index(conn, params) do
|
||||||
render(conn, "index.html", auth_mode: Livebook.Config.auth_mode())
|
render(conn, "index.html", auth_mode: Livebook.Config.auth_mode(), errors: params["errors"])
|
||||||
end
|
end
|
||||||
|
|
||||||
def authenticate(conn, %{"password" => password}) do
|
def authenticate(conn, %{"password" => password}) do
|
||||||
|
@ -25,7 +25,7 @@ defmodule LivebookWeb.AuthController do
|
||||||
if AuthPlug.authenticated?(conn, :password) do
|
if AuthPlug.authenticated?(conn, :password) do
|
||||||
redirect_to(conn)
|
redirect_to(conn)
|
||||||
else
|
else
|
||||||
index(conn, %{})
|
render_form_error(conn)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -35,10 +35,16 @@ defmodule LivebookWeb.AuthController do
|
||||||
if AuthPlug.authenticated?(conn, :token) do
|
if AuthPlug.authenticated?(conn, :token) do
|
||||||
redirect_to(conn)
|
redirect_to(conn)
|
||||||
else
|
else
|
||||||
index(conn, %{})
|
render_form_error(conn)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp render_form_error(conn) do
|
||||||
|
index(conn, %{
|
||||||
|
"errors" => [{"%{auth_mode} is invalid", [auth_mode: Livebook.Config.auth_mode()]}]
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
defp redirect_to(conn) do
|
defp redirect_to(conn) do
|
||||||
conn
|
conn
|
||||||
|> then(fn conn ->
|
|> then(fn conn ->
|
||||||
|
|
|
@ -19,10 +19,18 @@
|
||||||
<form method="post" class="flex flex-col space-y-4 items-center">
|
<form method="post" class="flex flex-col space-y-4 items-center">
|
||||||
<input type="hidden" value="<%= Phoenix.Controller.get_csrf_token() %>" name="_csrf_token"/>
|
<input type="hidden" value="<%= Phoenix.Controller.get_csrf_token() %>" name="_csrf_token"/>
|
||||||
<%= if @auth_mode == :password do %>
|
<%= if @auth_mode == :password do %>
|
||||||
|
<div phx-feedback-for="password" class="<%= if(@errors, do: "show-errors", else: "") %>">
|
||||||
<input type="password" name="password" class="input" placeholder="Password" autofocus />
|
<input type="password" name="password" class="input" placeholder="Password" autofocus />
|
||||||
<% else %>
|
<% else %>
|
||||||
|
<div phx-feedback-for="token" class="<%= if(@errors, do: "show-errors", else: "") %>">
|
||||||
<input type="text" name="token" class="input" placeholder="Token" autofocus />
|
<input type="text" name="token" class="input" placeholder="Token" autofocus />
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<%= for error <- @errors || [] do %>
|
||||||
|
<span class="mt-1 hidden text-red-600 text-sm phx-form-error:block">
|
||||||
|
<%= translate_error(error) %>
|
||||||
|
</span>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
<button type="submit" class="button-base button-blue">
|
<button type="submit" class="button-base button-blue">
|
||||||
Authenticate
|
Authenticate
|
||||||
</button>
|
</button>
|
||||||
|
|
Loading…
Add table
Reference in a new issue