From c4d06d877ea979dca5da2ec106d0597c80cd47df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 16 Apr 2021 22:17:54 +0200 Subject: [PATCH] Move auth to its own view Prior to this PR the HTML head was being included twice on the password auth page. One from root.html and another from the error page, so we decoupled those. --- .../controllers/auth_controller.ex | 4 +- .../templates/auth/index.html.eex | 23 ++++++++++ lib/livebook_web/templates/error/401.html.eex | 45 ++++++------------- lib/livebook_web/templates/error/404.html.eex | 4 +- lib/livebook_web/templates/error/500.html.eex | 4 +- .../templates/layout/app.html.eex | 1 - .../templates/layout/app.html.leex | 1 + lib/livebook_web/views/auth_view.ex | 3 ++ 8 files changed, 46 insertions(+), 39 deletions(-) create mode 100644 lib/livebook_web/templates/auth/index.html.eex delete mode 100644 lib/livebook_web/templates/layout/app.html.eex create mode 100644 lib/livebook_web/templates/layout/app.html.leex create mode 100644 lib/livebook_web/views/auth_view.ex diff --git a/lib/livebook_web/controllers/auth_controller.ex b/lib/livebook_web/controllers/auth_controller.ex index 13521daaa..38c9bc9b4 100644 --- a/lib/livebook_web/controllers/auth_controller.ex +++ b/lib/livebook_web/controllers/auth_controller.ex @@ -14,9 +14,7 @@ defmodule LivebookWeb.AuthController do end def index(conn, _params) do - conn - |> put_view(LivebookWeb.ErrorView) - |> render("401.html") + render(conn, "index.html") end def authenticate(conn, %{"password" => password}) do diff --git a/lib/livebook_web/templates/auth/index.html.eex b/lib/livebook_web/templates/auth/index.html.eex new file mode 100644 index 000000000..aa60d9e03 --- /dev/null +++ b/lib/livebook_web/templates/auth/index.html.eex @@ -0,0 +1,23 @@ +
+
+ + livebook + +
+ Authentication required +
+ +
+ Type password to access the Livebook. +
+
+
+ + + +
+
+
+
diff --git a/lib/livebook_web/templates/error/401.html.eex b/lib/livebook_web/templates/error/401.html.eex index 1ad0b3a60..ab66d90c9 100644 --- a/lib/livebook_web/templates/error/401.html.eex +++ b/lib/livebook_web/templates/error/401.html.eex @@ -4,8 +4,8 @@ - <%= live_title_tag "Livebook" %> - "/> + <%= @status %> - Livebook + "/>
@@ -17,36 +17,19 @@ Authentication required
- <%= case Application.fetch_env!(:livebook, :authentication_mode) do %> - <% :token -> %> -
- Please check out the console for authentication URL - or type the token directly here. -
+
+ Please check out the console for authentication URL + or type the token directly here. +
-
-
- - -
-
- - <% :password -> %> -
- Type password to access the Livebook. -
-
-
- - - -
-
- <% end %> +
+
+ + +
+
diff --git a/lib/livebook_web/templates/error/404.html.eex b/lib/livebook_web/templates/error/404.html.eex index 114a8e116..c42743caa 100644 --- a/lib/livebook_web/templates/error/404.html.eex +++ b/lib/livebook_web/templates/error/404.html.eex @@ -4,8 +4,8 @@ - <%= live_title_tag "Livebook" %> - "/> + <%= @status %> - Livebook + "/>
diff --git a/lib/livebook_web/templates/error/500.html.eex b/lib/livebook_web/templates/error/500.html.eex index 70825812b..125c453dd 100644 --- a/lib/livebook_web/templates/error/500.html.eex +++ b/lib/livebook_web/templates/error/500.html.eex @@ -4,8 +4,8 @@ - <%= live_title_tag "Livebook" %> - "/> + <%= @status %> - Livebook + "/>
diff --git a/lib/livebook_web/templates/layout/app.html.eex b/lib/livebook_web/templates/layout/app.html.eex deleted file mode 100644 index 05433985b..000000000 --- a/lib/livebook_web/templates/layout/app.html.eex +++ /dev/null @@ -1 +0,0 @@ -<%= @inner_content %> diff --git a/lib/livebook_web/templates/layout/app.html.leex b/lib/livebook_web/templates/layout/app.html.leex new file mode 100644 index 000000000..f3985a1e8 --- /dev/null +++ b/lib/livebook_web/templates/layout/app.html.leex @@ -0,0 +1 @@ +<%= @inner_content %> \ No newline at end of file diff --git a/lib/livebook_web/views/auth_view.ex b/lib/livebook_web/views/auth_view.ex new file mode 100644 index 000000000..aecfacf01 --- /dev/null +++ b/lib/livebook_web/views/auth_view.ex @@ -0,0 +1,3 @@ +defmodule LivebookWeb.AuthView do + use LivebookWeb, :view +end