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.
This commit is contained in:
José Valim 2021-04-16 22:17:54 +02:00
parent d00393ca86
commit c4d06d877e
8 changed files with 46 additions and 39 deletions

View file

@ -14,9 +14,7 @@ defmodule LivebookWeb.AuthController do
end end
def index(conn, _params) do def index(conn, _params) do
conn render(conn, "index.html")
|> put_view(LivebookWeb.ErrorView)
|> render("401.html")
end end
def authenticate(conn, %{"password" => password}) do def authenticate(conn, %{"password" => password}) do

View file

@ -0,0 +1,23 @@
<div class="h-screen flex items-center justify-center bg-gray-900">
<div class="flex flex-col space-y-4 items-center">
<a href="/">
<img src="/logo.png" height="128" width="128" alt="livebook" />
</a>
<div class="text-2xl text-gray-50">
Authentication required
</div>
<div class="max-w-2xl text-center text-gray-300">
Type password to access the Livebook.
</div>
<div class="text-2xl text-gray-50 w-full pt-2">
<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="password" name="password" class="input" placeholder="Password" />
<button type="submit" class="button button-blue">
Authenticate
</button>
</form>
</div>
</div>
</div>

View file

@ -4,8 +4,8 @@
<meta charset="utf-8"/> <meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/> <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<%= live_title_tag "Livebook" %> <title><%= @status %> - Livebook</title>
<link phx-track-static rel="stylesheet" href="<%= Routes.static_path(@conn, "/css/app.css") %>"/> <link rel="stylesheet" href="<%= Routes.static_path(@conn, "/css/app.css") %>"/>
</head> </head>
<body> <body>
<div class="h-screen flex items-center justify-center bg-gray-900"> <div class="h-screen flex items-center justify-center bg-gray-900">
@ -17,36 +17,19 @@
Authentication required Authentication required
</div> </div>
<%= case Application.fetch_env!(:livebook, :authentication_mode) do %> <div class="max-w-2xl text-center text-gray-300">
<% :token -> %> Please check out the console for authentication URL
<div class="max-w-2xl text-center text-gray-300"> or type the token directly here.
Please check out the console for authentication URL </div>
or type the token directly here.
</div>
<div class="text-2xl text-gray-50 w-full pt-2"> <div class="text-2xl text-gray-50 w-full pt-2">
<form method="get" class="flex flex-col space-y-4 items-center"> <form method="get" class="flex flex-col space-y-4 items-center">
<input type="text" name="token" class="input" placeholder="Token" /> <input type="text" name="token" class="input" placeholder="Token" />
<button type="submit" class="button button-blue"> <button type="submit" class="button button-blue">
Authenticate Authenticate
</button> </button>
</form> </form>
</div> </div>
<% :password -> %>
<div class="max-w-2xl text-center text-gray-300">
Type password to access the Livebook.
</div>
<div class="text-2xl text-gray-50 w-full pt-2">
<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="password" name="password" class="input" placeholder="Password" />
<button type="submit" class="button button-blue">
Authenticate
</button>
</form>
</div>
<% end %>
</div> </div>
</div> </div>
</body> </body>

View file

@ -4,8 +4,8 @@
<meta charset="utf-8"/> <meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/> <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<%= live_title_tag "Livebook" %> <title><%= @status %> - Livebook</title>
<link phx-track-static rel="stylesheet" href="<%= Routes.static_path(@conn, "/css/app.css") %>"/> <link rel="stylesheet" href="<%= Routes.static_path(@conn, "/css/app.css") %>"/>
</head> </head>
<body> <body>
<div class="h-screen flex items-center justify-center bg-gray-900"> <div class="h-screen flex items-center justify-center bg-gray-900">

View file

@ -4,8 +4,8 @@
<meta charset="utf-8"/> <meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/> <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<%= live_title_tag "Livebook" %> <title><%= @status %> - Livebook</title>
<link phx-track-static rel="stylesheet" href="<%= Routes.static_path(@conn, "/css/app.css") %>"/> <link rel="stylesheet" href="<%= Routes.static_path(@conn, "/css/app.css") %>"/>
</head> </head>
<body> <body>
<div class="h-screen flex items-center justify-center bg-gray-900"> <div class="h-screen flex items-center justify-center bg-gray-900">

View file

@ -1 +0,0 @@
<%= @inner_content %>

View file

@ -0,0 +1 @@
<%= @inner_content %>

View file

@ -0,0 +1,3 @@
defmodule LivebookWeb.AuthView do
use LivebookWeb, :view
end