mirror of
https://github.com/livebook-dev/livebook.git
synced 2024-11-16 12:57:32 +08:00
c4d06d877e
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.
35 lines
745 B
Elixir
35 lines
745 B
Elixir
defmodule LivebookWeb.AuthController do
|
|
use LivebookWeb, :controller
|
|
|
|
plug :require_unauthenticated_password
|
|
|
|
alias LivebookWeb.AuthPlug
|
|
|
|
defp require_unauthenticated_password(conn, _opts) do
|
|
if Livebook.Config.auth_mode() != :password or AuthPlug.authenticated?(conn, :password) do
|
|
redirect_home(conn)
|
|
else
|
|
conn
|
|
end
|
|
end
|
|
|
|
def index(conn, _params) do
|
|
render(conn, "index.html")
|
|
end
|
|
|
|
def authenticate(conn, %{"password" => password}) do
|
|
conn = AuthPlug.store(conn, :password, password)
|
|
|
|
if AuthPlug.authenticated?(conn, :password) do
|
|
redirect_home(conn)
|
|
else
|
|
index(conn, %{})
|
|
end
|
|
end
|
|
|
|
defp redirect_home(conn) do
|
|
conn
|
|
|> redirect(to: "/")
|
|
|> halt()
|
|
end
|
|
end
|